I'm trying to upload files in a React application. The following is generate code from a postman request that is working fine:
var myHeaders = new Headers();
myHeaders.append("Cookie", "<insertCookiesHere>");
var formdata = new FormData();
formdata.append("file", fileInput.files[0], "/C:/Users/username/Downloads/image.png");
formdata.append("appname", "explorer");
formdata.append("path", "/myteam/squads/Test/");
formdata.append("offset", "0");
formdata.append("complete", "1");
formdata.append("filename", "image.png");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://ccfilecloud.domain.com/core/upload", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Here is what I'm doing with React which doesn't work. At this point, I'm hardcoding all of this in just to get a working version. From what I can tell I NEED the absolute path to the file on the users' system, or Postman doesn't work. So it has to be manually entered because the browser has no access to that information.
const formData = new FormData();
formData.append(
'file',
fileInputElement.current.files[0],
`/C:/Users/username/Downloads/image.png`
);
formData.append('appname', 'explorer');
formData.append('path', `/myteam/squads/Test/`);
formData.append('offset', '0');
formData.append('complete', '1');
formData.append('filename', 'image.png');
fetch(
`https://ccfilecloud.domain.com/core/upload`,
{
body: formData,
headers: {
Cookie: cookies,
},
method: 'POST',
redirect: 'follow',
}
);
The error I get is an invalid upload path. Grabbing cookies from a login request, parsing them, and using them rather than a normal token is weird, but it's working with other requests. Using form data also feels odd.
Has anyone else used the file cloud API or come across a similar issue with uploading files via form data?