question

aurelianr1 avatar image
aurelianr1 asked

how to make a partially update of metadata in java?

I tried to convert the following Patch request which Partially updates a metadata: [i] curl -v -X PATCH --data '{"description": "a test file", "name":"fooNew.jpg", "labels":["PHOTO", "test"]}' https://cdws.us-east-1.amazonaws.com/drive/v1/nodes/11jqgRBmPBKzlY6_bu9Pew --header 'Authorization: Bearer Atza|IQEBLjAsAhQ5zx7pKp9PCgCy6T1JkQjHHOEzpwIUQM' [/i] [b] in following java code: [/b] [i] BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCookieStore(cookieStore) .build(); StringBody metadata = new StringBody("{\"description\":"+"new desciption"+", \"name\":"+"new name"+",\"labels\":[\"PHOTO\", \"test\"]}", ContentType.APPLICATION_JSON); HttpEntity reqEntity = MultipartEntityBuilder.create() .addPart("metadata", metadata) .build(); CloseableHttpResponse response2 = null; try { HttpPatch login = new HttpPatch(" https://cdws.us-east-1.amazonaws.com/drive/v1/nodes/11jqgRBmPBKzlY6_bu9Pew"); login.addHeader("Host", " content-na.drive.amazonaws.com"); login.addHeader("Authorization", "Bearer " + accessToken); login.setEntity(reqEntity); response2 = httpclient.execute(login); HttpEntity entity = response2.getEntity(); InputStream in = entity.getContent(); StringBuilder sb = Utils.parseInputStream(in); System.out.println(sb); EntityUtils.consume(entity); JSONObject json = new JSONObject(sb.toString()); } catch (Exception e) { System.err.print(e.getMessage() ); } [/i] The java code is used to update partially a metadata (see reference). It is not throw an exception and returns a blank response instead the response from the above reference. Would you give me a hint about how to update the java code to have the same behavior like the cURL request?[i][/i] Message was edited by: aurelianr1 Message was edited by: aurelianr1 Message was edited by: aurelianr1
amazon drive
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jamie Grossman avatar image
Jamie Grossman answered
Hi there, Thanks for getting in touch. Let me investigate further and I'll get back to you as soon as I have more information. Regards, Jamie
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jamie Grossman avatar image
Jamie Grossman answered
Hi there, Thanks for your patience. You seem to be using Java to build HTTP requests, and not just the Java classes. I would recommend the Java in the Android SDK. You shouldn't need all of it, but some of it would probably be useful. You will find "UpdateNodeRequest" and "UpdateNodeResponse" classes in there. For more information, please see below: https://developer.amazon.com/public/apis/experience/cloud-drive/reference/sdk-android-reference https://developer.amazon.com/public/binaries/content/assets/javadoc/amazon-cloud-drive-sdk-for-android/com/amazon/clouddrive/model/updatenoderequest.html https://developer.amazon.com/public/binaries/content/assets/javadoc/amazon-cloud-drive-sdk-for-android/com/amazon/clouddrive/model/updatenoderesponse.html Regards, Jamie
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

aurelianr1 avatar image
aurelianr1 answered
Hello Jamie. I will take a look at the mobile documentation
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

aurelianr1 avatar image
aurelianr1 answered
Hello Jamie I looked over the the mobile sdk but my problem remains because i want to use the code into a java application and I do not know how to update the above code to work from a java core application. Best regards, Aurelian
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jamie Grossman avatar image
Jamie Grossman answered
Hi there, You don't need to use all of it, but some of it would probably be useful. As stated, we have "UpdateNodeRequest" and "UpdateNodeResponse" classes in there which you should be able to use within your app. If you could let me know what issues you're running into, I can try and investigate further. Jamie
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.