Examples¶
Here are examples of uploading files.
Upload Source Code in a ZIP File¶
Request using the ‘curl’ command:
curl -X POST \
-H "Token:d29483e6c73033b309a1fe02b6e982fd042c6a70" \
-H "Content-Type:multipart/form-data" \
"https://secure.cigital.com/api/public/v3/TEST_123456789/files?\
fileUpload=source_code.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 uploadFile( String file ) {
Client client =
ClientBuilder.newBuilder().register( MultiPartFeature.class ).build();
WebTarget target =
client.target(MSP_URL).path( "/api/public/v3/"+scanId+"targets" );
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/file" );
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 )
.post( Entity.entity( multiPart,
MediaType.MULTIPART_FORM_DATA ) );
if ( response.getStatus() == 200 ) {
String response = 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": "source_code.zip",
"file_id": "5a0935c4a1e1072d81292c85"
}
]
Upload an Android App¶
Request:
curl -X POST\
-H "Token:d29483e6c73033b309a1fe02b6e982fd042c6a70"\
-H "Content-Type:multipart/form-data"\
"https://secure.cigital.com/api/public/v3/file?\
fileUpload=clans.apk"
Response:
Status: 200
Response Body:
[
{
"file_name": "clans.apk",
"file_id": "5a0935d4a1e1072d81292c92"
}
]
Parent topic:File Upload