Get status of an upload to Drive REST API - file-upload

I am creating a form in HTML5 and using Drive API rest to upload files, but the files are large, so I need to consult the current status of the upload. I'm using uploadType = resumable, but to make the status request as documentation:
[Google documentation][1]
PUT} {session_uri HTTP / 1.1
Content-Length: 0
Content-Range: bytes * / *
The response from the server does not return the Range received.
Does anyone know how to fix this?

Related

How to send File via Telegram Bot

I need to send txt File using TelegramBot API .
I already tried https://api.telegram.org/botMYT0KEN/sendDocument?chat_id=569502265&document=/Users/users/Desktop/file.txt
and have issue :
{"ok":false,"error_code":400,"description":"Bad Request: wrong remote
file id specified: Wrong string length”}
To complete Donny's answer, I would like to add an example of sending .txt file as a document.
Looks like you're using OS X as an operating system, which has curl utility preinstalled.
Open terminal and make a request like this:
curl -v -F "chat_id=569502265" -F document=#/Users/users/Desktop/file.txt https://api.telegram.org/bot<TOKEN>/sendDocument
From Telegram official documentation
Sending files There are three ways to send files (photos, stickers, audio, media, etc.):
If the file is already stored somewhere on the Telegram servers, you
don't need to reupload it: each file object has a file_id field,
simply pass this file_id as a parameter instead of uploading. There
are no limits for files sent this way. Provide Telegram with an HTTP
URL for the file to be sent. Telegram will download and send the file.
5 MB max size for photos and 20 MB max for other types of content.
Post the file using multipart/form-data in the usual way that files
are uploaded via the browser. 10 MB max size for photos, 50 MB for
other files. Sending by file_id
It is not possible to change the file type when resending by file_id.
I.e. a video can't be sent as a photo, a photo can't be sent as a
document, etc. It is not possible to resend thumbnails. Resending a
photo by file_id will send all of its sizes. file_id is unique for
each individual bot and can't be transferred from one bot to another.
Sending by URL
When sending by URL the target file must have the correct MIME type
(e.g., audio/mpeg for sendAudio, etc.). In sendDocument, sending by
URL will currently only work for gif, pdf and zip files. To use
sendVoice, the file must have the type audio/ogg and be no more than
1MB in size. 1–20MB voice notes will be sent as files. Other
configurations may work but we can't guarantee that they will.
https://core.telegram.org/bots/api
This is what you need from your question:
Post the file using multipart/form-data in the usual way that files
are uploaded via the browser. 10 MB max size for photos, 50 MB for
other files
You have to use the POST method instead GET. For example, I use https://github.com/php-curl-class/php-curl-class
$url = 'https://api.telegram.org/bot'.$botId.'/sendDocument';
$curl = new Curl();
$curl->post($url, [
"chat_id" => $chatId,
"document" => new \CURLFile($file_path)
]);

REST API - HTTP status for a partial response

I encounter the following case:
I have an API that allows me to retrieve a unique resource:
GET myapi/resource_id
If this resource does not exist, I return a 404 HTTP status code.
This API also allows to retrieve several resources via the same request:
GET myapi/resource_id1,resource_id2
Which HTTP status code should I send back if one of the two resources does not exist?
200 with an explanation in the JSON in an error key
206 which allows to be more explicit with an explanation in the JSON in an error key
400 / 404 code but this is not fine because the API still returns one of the two information
another solution?
Thank you for your help.
I think there are 2 options here.
Send back 200 and don't even mention the missing resource.
Send back 404 with an empty body.
The 206 is for range requests, the 400 is for malformed requests, so none of those apply here.

YouTube API 2.0 and 3.0 Returning different rresults

I'm working on a website that retrieves public videos from a YouTube channel to populate a video list on the site.
The published page is using the 2.0 version of the API with a base request URL of: http://gdata.youtube.com/feeds/api/users/z8xDwdqXrHVc-8b4ZsA0Sw/uploads?max-results=15
This URL successfully returns the 6 public videos available on the specified channel.
I'm in the process of migrating to the 3.0 API, and I've noticed a discrepancy in the results returned from the new request:
$searchResults = $youtube -> search -> listSearch( 'snippet', array(
'channelId' => 'UCz8xDwdqXrHVc-8b4ZsA0Sw',
'maxResults' => 15,
'type' => 'video'
) );
With this request, I would expect $searchResults to contain the same 6 videos as the old 2.0 API request, however, the 3.0 request returns a response with zero results.
I am reasonably certain that I have ruled out an error in my setup of the Google_Service_YouTube and Google_Client objects.
I replaced the channelId parameter above with the channel ID of my own personal YouTube channel (UC2qJ2qvc_fRp3xLtWKNPucw), and received a response with the 10 public videos I have on that channel.
What would cause this discrepancy?
EDIT
Since making this post, I have removed all videos from the channel in question. The videos were originally uploaded using the export feature available through twitch.tv. I downloaded the original files and resubmitted the videos directly through YouTube, and now all 6 videos appear in the API response as expected.
At this point, I've got the feed working and developed a plan for video upload management that should prevent this from resurfacing. However, I'd still like to understand what would cause the inconsistency. Why would videos uploaded to the channel via Twitch be excluded from the search results?

How do I delete file that I have uploaded on Cloudinary using Jquery?

Can someone advise me how to delete a file in Cloudinary using Jquery?
I can't find any sample snippets to get started.
There good documentation on deleting client side uploaded images.
There are a few caveats to note though:
This does not work with unsigned uploads.
You will have to set return_delete_token: 1 in the options during your file upload, then pass the returned image's delete_token to the cloudinary.delete_by_token(delete_token) method.
From the documentation, you can do this over REST like so: curl https://api.cloudinary.com/v1_1/demo/delete_by_token -X POST --data 'token=delete_token'
Deleting resources requires an authenticated API (including a signature). Since the signature is based on your account's api_secret which shouldn't be included in your client-side code, you'll need to generate the signature on the server-side.
Having said that, when uploading you can set the new return_delete_token to true to tell Cloudinary to return a deletion token as part of the upload response.
The token can be used to delete the uploaded image within 10 minutes using an unauthenticated API request.
This is done with the delete_by_token method. See the following for a reference:
https://github.com/cloudinary/cloudinary_js/blob/47cf97a07f063a32311ff7d7cd09dc5a5a919318/js/jquery.cloudinary.js#L598

Google Drive API Permissions Insert sendNotificationEmails Bad Request

I'm working with the google-api-php-client Library for Google Drive (LIBVER = "1.0.5-beta") and when I issue this:
$permission = new Google_Service_Drive_Permission();
$permission->setType('user');
$permission->setValue($email);
$permission->setRole($role);
$service->permissions->insert($folder_id, $permission, array('sendNotificationEmails'=>false));
I get a Bad Request 400 error back.
With all the same settings, if I remove the sendNotificationEmails option, it works fine. The client library does not seem to be doing much more than appending that as a querystring value to the POST request, so could it be a bug in the API?