Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset upload does not allow specifying attributes #32

Closed
GriffinCodes opened this issue Jul 25, 2023 · 4 comments
Closed

Asset upload does not allow specifying attributes #32

GriffinCodes opened this issue Jul 25, 2023 · 4 comments

Comments

@GriffinCodes
Copy link

Executing the following cURL uploads an image to my stack's assets inside the specified folder

curl --location 'https://api.contentstack.io/v3/assets' \
--header 'api_key: API_KEY' \
--header 'authorization: MANAGEMENT_TOKEN' \
--header 'Content-Type: multipart/form-data' \
--form 'asset[upload]=@"/path/to/image.jpg"' \
--form 'asset[parent_uid]="PARENT_FOLDER_UID"' \
--form 'asset[title]="Test2_3"'

While the javadocs note the form field's existence, it does not appear to allow me to fill in the form field, causing the image to be uploaded to the root folder. Please let me know if I'm missing something.

@ishaileshmishra
Copy link
Contributor

ishaileshmishra commented Jul 27, 2023

Hi @GriffinCodes , Thank you for raising this issue; we truly appreciate your valuable feedback. Rest assured, we will thoroughly investigate the matter to understand and address it appropriately. meanwhile i would suggest you to try using
asset.addHeader("", ""); like below.

asset.addHeader("cache-control", "no-cache") ;
asset.addHeader("content-type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
asset.addHeader("asset[upload]", "@{Filepath e.g., /C:/Users/abc/Desktop/Sample.png}");
asset.addHeader("asset[parent_uid]", "blt87347767634");
asset.addHeader("asset[title]", "If needed, enter a title for your uploaded asset");
asset.addHeader("asset[description]", "If needed, enter a description for your uploaded asset");
asset.addHeader("asset[tags]", "If needed, assign a specific tag to your uploaded asset");

Example:

Asset asset = client.stack("API_KEY", "ManagementToken").asset();
Response<ResponseBody> response = asset.uploadAsset("filepath", "description").addHeader("", "").execute();

hope this will help you !

@GriffinCodes
Copy link
Author

Adding the asset[] headers causes the API to respond with 400 Bad Request. According to the API spec, they should be form fields, not headers

@ishaileshmishra
Copy link
Contributor

Thanks for checking @GriffinCodes. We are working on resolving the issue, and we will provide an update here once it is fixed.

This was referenced Jul 28, 2023
ishaileshmishra added a commit that referenced this issue Jul 31, 2023
Aug 01, 2023
- Bug Fixed For un-localize An Entry
- Fixed Timeout Issue
- #32 Fixed
- Code coverage improvements
- NRP support added
- General improvements with minor breaking changes
ishaileshmishra added a commit that referenced this issue Jul 31, 2023
Aug 01, 2023
- Bug Fixed For un-localize An Entry
- Fixed Timeout Issue
- #32 Fixed
- Code coverage improvements
- NRP support added
- General improvements with minor breaking changes
ishaileshmishra added a commit that referenced this issue Jul 31, 2023
Aug 01, 2023
- Bug Fixed For un-localize An Entry
- Fixed Timeout Issue
- #32 Fixed
- Code coverage improvements
- NRP support added
- General improvements with minor breaking changes
@ishaileshmishra
Copy link
Contributor

Hi @GriffinCodes, We have uploaded a new build of the Management SDK. Please let us know if it resolves the issue.

Update your pom file dependency to 1.0.0

<!-- https://mvnrepository.com/artifact/com.contentstack.sdk/cms -->
<dependency>
    <groupId>com.contentstack.sdk</groupId>
    <artifactId>cms</artifactId>
    <version>1.0.0</version>
</dependency>

Use below code snippet for assetUpload():

String description = "What is Lorem Ipsum?"; // your title
String filePath = "/Users/shaileshmishra/Desktop/resources/asset.png"; // the image/file path you want to upload
Contentstack client = new Contentstack.Builder().build(); // create client instance 

Stack stack = client.stack("apiKey", "managementToken"); // get stack instance using client
Response<ResponseBody> upload = stack.asset() // get asset using stack instance
.addParam("key", "value")   // add params if needed (Optional)
.addHeader("header", "value") // add headers if needed (Optional)
.uploadAsset(filePath, description).execute();  // execute uploadAsset
String[] tags = {"contentstack", "cms", "management", "world"};  // prepare tags if you want to pass else pass null 

Response<ResponseBody> assetUpload = stack.asset().
      uploadAsset(filePath, "asset_parent_id", "Fake Image", "Something as description", tags).execute();

if(assetUpload.isSuccessful){
     System.out.println("response: "+uploadMultiple.body()); // print the response
}

Feel free to reopen the ticket if the issue still persists.

thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants