I am using AWS JAVA SDK to automate calls to device farm. I have successfully created project, created upload and generated S3 pre-signed url, but now I have to send the IPA file using this pre-signed url.
Here is my code, please let me know what I am doing wrong. I think I am not sending the file in a correct way to server. Please share the sample of code for sending the file using pre-signed url. I already tried many different ways to send file to device farm.
Any help will be appreciated.
AWSCredentials awsCredentials=new BasicAWSCredentials("sampleJRMSWANJS5KQ","sampleUSNnuC/fVSgvR9DSVr");
AWSDeviceFarm deviceFarmObj = new AWSDeviceFarmClient(awsCredentials);
CreateProjectRequest projReqObj = new CreateProjectRequest();
projReqObj.setName("JAVAHTTPAWSAPIPROJECT");
Project projObj = deviceFarmObj.createProject(projReqObj).getProject();
String projArn=projObj.getArn();
byte[] array = Files.readAllBytes(new File("/Users/abc/Documents/Card/Blue.ipa").toPath());
String data = new String(array,"UTF-8");
char[] charFile= data.toCharArray();
URL urlPreSigned = new URL(url);
HttpURLConnection connection=(HttpURLConnection)urlPreSigned.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
OutputStreamWriter out = new OutputStreamWriter(
connection.getOutputStream());
out.write(charFile);
out.close();
int responseCode = connection.getResponseCode();
System.out.println("Service returned response code " + responseCode);
Below is the reference to the code to upload an app from Device Farm Jenkins plugin. https://github.com/awslabs/aws-device-farm-jenkins-plugin/blob/master/src/main/java/org/jenkinsci/plugins/awsdevicefarm/AWSDeviceFarm.java#L367
Let us know if you need any other information