Examples¶
Here are examples of updating a file.
Update Source Code contained in a ZIP File¶
Request using the ‘curl’ command:
curl -X PUT \
-H "Token:d29483e6c73033b309a1fe02b6e982fd042c6a70" \
-H "Content-Type:multipart/form-data" \
"https://secure.cigital.com/api/public/v3/scans/TEST_123456789/files?\
ComparePlugin.v1.5.6.2.bin.zip"
Request using an Apache Groovy script:
// NOTE: Environment (env) and other variables have to be
// defined beforehand.
def filecontent = """${sh(
returnStdout: true,
script: "curl -X POST '${env.HostUrl}/api/public/v3/'+(env.testId)+'/files'
-H 'accept: application/json' -H 'token: ${env.token}'
-H 'Content-Type: multipart/form-data' -F 'upfile1=@${fileName}'"
)}""".trim()
Request using Java source code:
public void fileUpdate( String scanId,
String file) {
Client client =
ClientBuilder.newBuilder()
.register( MultiPartFeature.class )
.build();
MultiPart multiPart = null;
File uploadFile = null;
try {
if ( file.contains( "http" ) ) {
BufferedInputStream in =
new BufferedInputStream( new URL( file ).openStream() );
FileOutputStream fis = new FileOutputStream( "ips.txt" );
byte[] buffer = new byte[1024];
int count = 0;
while ( ( count = in.read( buffer, 0, 1024 ) ) != -1 ) {
fis.write(buffer, 0, count);
}
} else {
uploadFile = new File(file);
}
WebTarget server =
client.target( MSP_URL )
.path( "/api/public/v3/scans/"+scanId+"/files" );
multiPart = new MultiPart();
FileDataBodyPart zipBodyPart =
new FileDataBodyPart( "file",
uploadFile,
MediaType.MULTIPART_FORM_DATA_TYPE );
multiPart.bodyPart( zipBodyPart );
Response response =
server.request( MediaType.APPLICATION_JSON )
.header( "token", MSP_TOKEN )
.put( Entity.entity( multiPart,
MediaType.MULTIPART_FORM_DATA ) );
if ( response.getStatus() == 200 ) {
System.out.println(response.readEntity(String.class));
} else {
System.out.println("Failed to upload the file. ");
}
} catch ( FileNotFoundException fnf ) {
System.out.println( "File Not Found" );
} catch ( IOException ioe ) {
System.out.println( "IO Exception Found " );
} finally {
client.close();
}
}
Response:
Status: 200
Response Body:
[
{
"file_name": "ComparePlugin.v1.5.6.2.bin.zip",
"file_id": "5b068f93cbce1d55ac50a8c5"
}
]
Parent topic:File Update