How to upload video from the API imgur

别说谁变了你拦得住时间么 提交于 2021-01-28 04:40:28

问题


I'm using imgur API and I have several question, what is the size limit for uploading a .gif ? I read everywhere the size limit of picture is 10Mb and gif are 20Mb but when I try to upload a gif of 11Mb with the API it tells me it's too heavy.

Also Im trying to upload a video (.mp4 , 6,9Mb) and I use the following request with postman

https://api.imgur.com/3/image?client_id={myclientid}

and in the body

  video={mavideo.mp4}

but it return me a success with no information

{
"data": {
"errorCode": null,
"ticket": "90c70cdc"
},
"success": true,
"status": 200
}

I have followed the api documentation to make this request

Thank you.

EDIT:

Ok it work if I'm using https://api.imgur.com/3/upload in postman but when I try to use it with ajax like this

if (fileExtension == "mp4" || fileExtension == "webm"){
     form.append('video', file);
    } else {
     form.append('img', file);
    }
$.ajax({
     url: 'https://api.imgur.com/3/upload',
     headers: {
     Authorization: "Client-ID " + ClientId },
     type: 'POST',
     data: form,
     cache: false,
     contentType: false,
     processData: false
 })

I have got the message Access to XMLHttpRequest at 'https://api.imgur.com/3/upload' from origin 'http://localhost:3010' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. What is wrong ?


回答1:


Not really an answer, but we both seem to be trying to get this working at the same time, so i will share what i found out.

As you seem to have found out also, there are 2 endpoints for uploading, /image and /upload.

When uploading video, /image returns a ticket id. This is probably meant to get the state of the queued processing. There is however no endpoint available where you can send the ticket id and get the state back.

Second endpont, /upload has however another bunch of issues.

While it does return a more useable object with image id and url, it seems to completely ignore the authorization header. Any image that i managed to upload this way has null for the uploaded user, and i don't see it in my account. (using oauth2 and sending Authorization: Bearer <token>) Even if i omit the header completely, it still works even though Authorization is mandatory for uploading.

Another weird thing is, if i don't send the auth header BUT add anything to the query params (so ?some=thing or whatever) it suddenly wakes up and starts requiring the authorization header. When i send it again at this point however, we are back at the beginning and even the /upload endpoint starts sending ticket id and not a reasonable response.




回答2:


This is a CORS issue and needs to be fixed by the imgur devs. It's only an issue when doing client-side JavaScript as curl works just fine:

echo 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' | base64 --decode | curl --location --request POST 'https://api.imgur.com/3/upload' --header "Authorization: Client-ID $CLIENT_ID" -F 'type=file' -F 'disable_audio=0' -F 'image=@-'


来源:https://stackoverflow.com/questions/57233881/how-to-upload-video-from-the-api-imgur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!