I have a problem with using Imgur API. I received clientId for anon uploading of media files. Then I tried to use this credentials for API requests. I had problems with using 'https://api.imgur.com/3/upload' route for uploading from the client browser Javascript, but then I found that 'https://api.imgur.com/3/image' works as expected with images uploading (in base64 format), but not working as expected with video uploading (in binary format, because of base64 returns error), after changing method of sending video in binary format doing few requests I managed to receive 200 response code, but the only info I received (besides status info) was 'ticket' field, and nothing else (no error message or code). And I don't know how to use this info to get access to the uploaded video. This type of response not documented anywhere and I'm not really sure it should be working like it is now. Can you please help me with this case? Maybe someone had a similar situation. I have attached 'har' request info from Chrome so that you could see how I made a request, maybe I did mistake somewhere. Really waiting for your answer, thanks!
Send file function:
sendFile = async (fileObj) => {
const myHeaders = new Headers();
myHeaders.append('Authorization', uploadCredentials);
const formData = new FormData(),
{
type
} = fileObj,
fileTitle = fileObj.file.name.split('.').shift(),
splitDataMarker = ';base64,';
let fileData;
if (type === 'image') {
const indexOfMarker = fileObj.data.indexOf(splitDataMarker),
indexOfDataStart = indexOfMarker ? indexOfMarker + splitDataMarker.length : 0;
fileData = fileObj.data.substr(indexOfDataStart);
formData.append('type', 'base64');
} else if (type === 'video') {
formData.append('type', 'file');
const res = await fetch(fileObj.data);
fileData = await res.blob();
}
formData.append(type, fileData);
formData.append('name', fileObj.file.name);
formData.append('title', fileTitle);
const requestOptions: any = {
method: 'POST',
headers: myHeaders,
body: formData,
redirect: 'follow',
};
try {
const res = await fetch(uploadUrl, requestOptions),
data = await res.json();
return data;
} catch (error) {
throw Error(error);
}
},