Thank you. Adding those permissions allowed me to use the localFileSystem to point to the file I want to upload, but I still have been unsuccessful in executing the upload of the file via XHR or Fetch PUT calls to the presigned URL. This is the first panel that I have used API calls in. I have been able to read and write metadata to existing assets with XHR calls. I have also been successful in creating an asset with the following code:
var data = JSON.stringify({
"filename": "test.jpg",
"metadata": [
{
"metadataDefinitionId": idOne,
"metadataDefinitionValue": valueOne
},
{
"metadataDefinitionId": idTwo,
"metadataDefinitionValue": {
"valueId": valueTwo
}
}
],
"metadataTemplateId": tempId,
"securityTemplateIds": [
securityId
]
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", myUrl);
xhr.setRequestHeader("X-API-Key", keyContents);
xhr.setRequestHeader("Authorization", auth);
xhr.setRequestHeader("AccessToken", access);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
This XHR returns the presigned URL to upload the image to. I have attempted to use the PUT call to then upload to that presigned URL with the code below:
exportFile();
async function exportFile() {
const uxp = require('uxp');
const lfs = uxp.storage.localFileSystem;
let uploadFile = await lfs.getFileForOpening();
console.log(uploadFile);
try{
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("PUT", preSignedUrl);
xhr.setRequestHeader("Content-Type", "image/jpeg");
xhr.send(uploadFile);
}
catch(e){console.log(e);}
}
This errors with “unsupported body type”
I’ve also tried installing Axios and using this code:
var axios = require('axios');
var config = {
method: 'put',
url: preSignedUrl,
headers: {
'Content-Type': 'image/jpeg'
},
data : uploadFile
};
axios(config)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
This does not error but the response.data is “”, and the image still doesn’t upload.
Are there any API calls that could work to attach the image to the presigned URL?
A colleague was able to upload to this presigned URL with applescript and a curl command, but I am trying to do it from the UXP panel.
do shell script "curl -v --upload-file '" & filePath & "' '" & signedURL & "'"