Can we upload media files using URL in MediaFileUpload? - python-3.x

Basically all I want to know is, I am working on Youtube API to upload videos on my channel. Whenever I try to upload video from my local file, it works without any issue. But if I want to upload some videos which are already hosted on S3, it gives me error related to OS i.e. OSError: File not found at that location.
So is there any way to upload video using youtube API from already hosted URLs ?
P.S. I am following the documentation of youtube API and using MediaFileUpload to upload the video files.
Edit 1: I tried a minor hack around this particular issue and works fine for me. Just leaving it here for future developers.
import requests
from six import BytesIO
url = "" # The video url you want to upload (I use S3 urls, not sure if it will work with youtube urls)
res = requests.get(url)
file = BytesIO(res.content)
media = MediaIoBaseUpload(file, mimetype="application/octet-stream")

Related

Add sample image in template header in whatsapp cloud API

I am doing a project using WhatsApp cloud API. I need to create a template with a media header. I have created a template with a media header without a sample image and it gets rejected. So I want to create a template with a sample image in Node JS.
Template with a media header
Add sample image for a template
curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
?name={template-name}
&language=en_US
&category=TRANSACTIONAL,
&components=[{
type:BODY,
text:{message-text}
},
{
type:HEADER,
format:IMAGE,
example:{header_handle:[{uploaded-image-file-url}]}
}],
&access_token={system-user-access-token}"
I want to add a sample image using Node JS (Not manually like the second picture).
header_handle requires a encrypted file upload provided by facebook.
This can be done by calling 2 apis.
First,
We have to create a session for the file to be uploaded.
For creating session refer this
After creating session, we will get session id to upload the original file to it.Response will look something like this:
{"id":"upload:MTphdHRhY2htZW50Ojlk2mJiZxUwLWV6MDUtNDIwMy05yTA3LWQ4ZDPmZGFkNTM0NT8=?sig=ARZqkGCA_uQMxC8nHKI"}
Second,We have to upload the file to
https://graph.facebook.com/v14.0/{above_id}
This will give a response something similar to
{"h":"2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"}
Finally,
{header_handle:["2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"]}
Should be added during the request to create template.
It worked for me.
See this for better understanding on how to do it.
The answer Provided by Aravindh is correct, you can follow This document from Meta to upload the Image you want.
Just make sure you use a supported type by WhatsApp API ( For WhatsApp Business Platform Cloud API , For WhatsApp Business Platform On-Premises API ) and the upload end point (file-type — The file's MIME type. Valid values are: image/jpeg, image/jpg, image/png, and video/mp4
)
Double Check if you are following exacly the types supported, for example in case of png, you need to set "file_type" to "image/png" no just "png" when creating the upload session.
I have tested it and it works for me.
Hope this helps

AWS presigned URL fails when the video is longer than 1 minute

I tried creating a presigned URL for two videos in the same s3 bucket manually and I've set the expiration date to 7 days :
The first one (47,3 MO and 20 seconds long) is working perfectly.
First video url output
The second video (82,3 MO and 6 minutes long) is not working : It shows no error in the console
Second video url output
It is the same issue even when I use a lambda function to generate the presigned URLS.
My lambda function code in NodeJS
I found this issue that can help me but it's not solved either :
S3 presigned url fails when large files
Turned out it's the video's problem. the videos I was using were timelapes converted to MP4 and I guess the format wasn't right that's why it's not supported by S3

Send drive file to python telegram bot

I am trying to get my telegram bot to download a pdf document that is on google drive, but I can't get it to work.
I made the following code to be able to get it to work but there was no case in this:
url = bot.get_File(link='link of google drive') down = url.download() bot.sendDocument(chat_id=ChatId, document=open(down,'rb'), filename="Lista de precios.pdf")
I don't put the google drive link for privacy reasons, but obviously it would go there.
I don't know if it is possible to download a file from drive just like that.
Looks like you are using the wrong method, get_file is used to download a file from Telegram.
When sending a file via Telegram bot you can use the full URL if this points to a file (ie file.pdf)
bot.send_document(chat_id=Chat_id, document='https://github.com/user/project/raw/master/data/pdf/07-03-2020.pdf'
In case of Google Drive you have a URL that streams the file so you need to 1) download and save the file locally 2) open the local file and send it as file type
r = requests.get('googleDriveUrl', allow_redirects=True)
open('file.ppt', 'wb').write(r.content)
bot.send_document(chat_id=Chat_id, document=open('file.ppt', 'rb'), filename="file.pptx")

How to upload an mp4 (or other video) to Imgur using the API?

I am using the Imgur API to upload images to albums, as part of a Reddit bot. However, when I try to upload MP4 files I get an error: "File type invalid (1)". Uploading the exact same MP4 file using the website works just fine.
I am using this endpoint to upload the file: POST https://api.imgur.com/3/image
https://apidocs.imgur.com/#c85c9dfc-7487-4de2-9ecd-66f727cf3139
The above comment is no longer correct -- You can indeed upload an MP4 using Imgur API
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'))
The above works for me and uploads successfully. Something to note though, I have not figured out how to make the upload tied to my account, or within a specific album. It seems to be ignoring the album_id field. In other words, despite using the Bearer token, it appears to be navigating the API "anonymously".
From the imgur Help site, located here and last updated 2 months ago:
https://help.imgur.com/hc/en-us/articles/115000083326-What-files-can-I-upload-What-is-the-size-limit-
File Types
If you need help learning how to upload on Imgur, check out this help
article. You can upload any of the following files: JPEG, PNG, GIF, APNG, TIFF, MOV (desktop website only), MP4 (desktop website
only)
Imgur doesn't currently support uploads in the following
formats: WEBM GIFV
Explicitly, MP4s are only currently supported as uploaded manually via the website directly.
Unfortunately, that means imgur does not support MP4 types through any method other than the Desktop site at this current time.
I agree with a comment above. Now it is works great. Even you can upload the video without authorization. Just using a POST method https://api.imgur.com/3/upload. Pass a video file in body with image key. That's all.
Example in Postman

Unable to download video from Google Photos API baseUrl

I am trying to download a video from {baseUrl=dv}. ( URL 1 )
After that the page on this URL was redirected and getting a 500 error ( URL 2 ).
What's missing?
There is currently a known issue with base URLs for videos. Accessing the video via the dv parameter returns a 500 Error.
You can follow along on the issue tracker here: https://issuetracker.google.com/111638708 ("Star" the issue to be notified of any updates.)

Resources