Does the vimeo nodejs API support uploading using the 'pull' approach - node.js

I'm trying to use the pull approach for vimeo api uploading, but the vimeo UI shows the films 'uploading' forever, and none of the metadata I've included in the post request makes it to vimeo either.
My request looke like this (i've redacted some of it). The signedURL works and has an expiry of 1 day.
{
path: '/users/xxxxx/videos',
query: {
upload: {
approach: 'pull',
size: 27759876,
link: 'https://storage.googleapis.com/xxxxxx/xxxxxxx%2F0079e513eb90623236b9fce0ebdc5a29%2Ffilm%2F0079e513eb90623236b9fce0ebdc5a29.m4v?GoogleAccessId=xxxxxxxxxxxxxxxxxxxx&Expires=1599054191&Signature=jLEDJ8iNaRC4eDn37DHoCilhKMmDk04h17Vu%2FbDUJbNFxdbjR9CowMQWdn95MdrX....etc'
},
name: 'xxxx',
description: 'xxxxxxx',
privacy: {
download: true,
embed: 'private',
comments: 'nobody',
view: 'anybody'
}
},
method: 'post'
}
and the response back from vimeo appears valid - with lots of vimeo metadata and a vimeo id for the uploaded film.
Looking at the nodejs api on github I only see tus upload approach examples - so now I'm wondering if the client actually supports the pull approach. Has anyone been able to get it to work?

You'll want to use the params property instead of query; using params will put your metadata into the request body instead of providing it as a query parameter.
params is mentioned in the docs as part of the upload method, but it should be used with the request method when making a POST or PATCH.
I think your example request is fine, just swap params for query
https://github.com/vimeo/vimeo.js#uploading-videos
https://github.com/vimeo/vimeo.js/blob/c7a1a16c1805539a00bc37d661b81c10e2108a75/example/upload.js#L63

Related

Upload Video with the Imgur RapidAPI

So I know this question has been asked here before but not specifically with RapidAPI. Anyways, the RapidAPI page forwards the documentation to https://api.imgur.com/
which further forwards to https://apidocs.imgur.com/
where finally we can find the api endpoint https://api.imgur.com/3/upload
now this endpoint is not compatible with the rapid api because there is simply no /3/upload endpoint on rapidapi. although it is written in the documentation that /3/upload is the same as /3/image which would make https://api.imgur.com/3/upload into https://imgur-apiv3.p.rapidapi.com/3/image. Problem here is that when i make a request to this endpoint with a video instead of an image in the payload i get this response json:
{'data': {'error': 'Could not process upload!', 'request': '/3/image', 'method': 'POST'}, 'success': False, 'status': 500}
Which basically tells me that it cannot parse the file format because when uploading any type of image it works. So what's going on?
This works for me:
import requests
url = "https://api.imgur.com/3/upload"
payload = {'album': 'ALBUMID',
'type': 'file',
'disable_audio': '0'}
files = [
('video', open('/path/to/Video.mp4','rb'))
]
headers = {
'Authorization': 'Bearer BEARERTOKENHERE'
}
response = requests.request("POST", url, headers=headers, data = payload, files = files)
print(response.text.encode('utf8'))
As far as I can understand their API /3/upload is for video & image but requires a token to use.
/3/image is for images only and should be used for uploading anonymous images with no user authentication.
But I am not 100% sure about that since I was not able to get a token to upload to /upload myself. (since I wanted to upload to my account in a 2 legged OAuth which looks like is not supported?)
So what you would need to do is to call /auth to get your token, exchange this token for a BEARER TOKEN to use the /upload path.
Hope this explains it a bit.

nodejs - Getting 401 error trying to download docs revisions with Google Drive API export links

I need to download all the revisions of a google doc with the Drive API using nodejs but I don't understand how to authorize the request for the export links. Once I get the export link for each revision I call:
var options = {
url: 'https://docs.google.com/feeds/download/documents/export/Export?id=1DRl6rbcVuuLVyb_WlhBLiYiCByWcS2bKGlLIsn7E8_8&revision=1&exportFormat=txt', //example link
method: 'GET',
headers: {
Authorization: `Bearer ${jwToken}`,
},
}
request(options).pipe(fs.createWriteStream(mydownloadfilename));
where the "jwToken" is the token I use to get the revisions list so I guess it should be still valid. However, with this I get the 401-Unauthorized page. What am I doing wrong?
Thanks
According to the Drive API v3 documentation:
Revisions for Google Docs, Sheets, and Slides can't be downloaded.
So essentially, if the actual revision you want to retrieve is the file itself, then the method above is the correct one.
As for the authorization part, you will need to perform the Node.js Quickstart from here and follow the steps explained there.
Since you want to export the file, you will just need to modify the code and add this part:
function downloadDoc() {
var fileId = 'ID_OF_THE_DOC';
var dest = fs.createWriteStream('DESTINATION_OF_THE_OUTPUT_STREAM');
drive.files.export({
fileId: fileId,
mimeType: 'application/vnd.google-apps.document'
})
.on('end', function () {
console.log('Done');
})
.on('error', function (err) {
console.log('Error during download', err);
})
.pipe(dest);
}
Reference
Drive API v3 - Manage Revisions;
Drive API v3 - Files:export;
Drive API v3 - Quickstart;
Drive API v3 - Download a document.
I am facing this same problem. The solution is to use
OAUTH2 authorization for a user that has Edit or Owner permissions for a file
Get an access token that expires quickly
call the V2 URI (V3 does not work) for the file/rev to get "export links" 3) Call the correct export link for your format type
then you will get a randomized temporary redirect link from Google that you can then call to get the binary stream.
This is a great starting point for C# .NET -- windows oauth console app, if you want working code to do steps 1 and 2. I posted a working v2 code function here that you can put into the console app example.

How to upload video from the API imgur

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 ?
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.
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=#-'

How to POST image as form data using npm request?

I have a specific task: I need to download an image from the source URL and upload it to another host via POST request as multipart/form-data. I'm trying to use node.js request library but never succeed.
The following code doesn't send anything in the request body.
request.post({
url: uploadUrl,
formData: {
photo: request(imageUri)
}
}, function (err) {
if (err) console.error(err.stack)
});
I have tried posting directly through the form-data library, but it doesn't seem to work neither. How do I solve this without the creation of temp files?
As i said in my comment, you need to wait until you have the image to make the post request. If you wanted to pipe the streams, you could try something like this...
request.get(imageUri).pipe(request.post(uploadUri));
Hope that helps.
The problem turned out to be that my imageUri had query parameters in it. I think this is a bug in form-data library. Removing query parameters solved the problem.

Upload a photo to facebook album

I have a nodejs (+express + mongodb,gridstore) backend, and want to upload a photo to a facebook album.
I came across 2 methods. the first ( https://developers.facebook.com/blog/post/526/ ) needs to get the full url resource of my picture, which I don't have as it is data that I pull from gridstore,
and the second ( https://developers.facebook.com/docs/reference/api/album/ ) is very poorly documented, via the Graph API, where I can't figure out what my request should look like. (the form-data, what fields should it have, how to convert my data blob\stream from gridstore to it)
Here is what I currently have, and doesn't work:
facebook.uploadPhoto = function (token, albumId, photo, callback) {
var fb = fermata.json('https://graph.facebook.com/' + albumId);
fb.photos({access_token:token}).post({'Content-Type':"multipart/form-data"}, {source:{data:photo}}, callback);
};
Any help would be much appreciated
There is a good chance the file is not properly serialized. Fermata will take a node File buffer via data. Have you tried passing that instead?
fs.readFile("/path/to/photo.jpg", function (err, data) {
fermata.json("https://graph.facebook.com/graph/api").post({"Content-Type":"multipart/form-data"}, {fileField: {data:data, name:"", type:""} }, callback);
});
Adding your access token etc..
I solved this problem by using a simple POST to the facebook graph API using the poster module.
var options = {
uploadUrl: 'https://graph.facebook.com/'+user+'/photos?access_token='+accessToken,
method: 'POST',
fileId: 'source',
fields: {'message':''} // Additional fields according to graph API
};
var fileName = ''; // Local or remote url where to find the image
poster.post(fileName, options, function(err, data) {
if (err) {
//Something went wrong
} else {
// Everything ok
}
});
Honestly, I've got limited experience working with the Facebook graph API and mostly using PHP and Java.
Here is some streams that you might find helpful:
Upload Photo To Album with Facebook's Graph API
Facebook Graph API - upload photo using JavaScript
Basically, I recommend you punt a little in your implementation and code it in the following way:
Create a REST web service function call in Node.js to output a single image from gridstore using an internal UID.
Code your uploadToFacebook function to use an image URL that calls the REST web service function.
Basically, this would allow you to validate the image output by pointing your browser to the REST web service and avoid any blob\stream conversions inside your uploadToFacebook function. I'm assuming you store the image in gridstore vs. mongodb.
hope that helps...

Resources