Uploading Videos/mp4 to twitter using Java Application - java

I have succesfully posted images and messages in java application to twitter using twitter4j.jar by refering this link http://javapapers.com/core-java/post-to-twitter-using-java/ , now i am tring to upload video/mp4/chunk to twiiter.
I googled about this topic and found many answers-
Some posts says its not possible yet ,some say its possible through rest API ,some with twitvid API ,some with tweetinvi (http://tweetinvi.codeplex.com/discussions/640413)
My questions are:
1.) Is it possible to upload video to twiter?
2.) If yes,is it possible only through Rest API or(is it possible using twitter.media support jar in twitter4j).
Any suggestion, answer, post regarding this are welcomed and thanked.

I am the developer of Tweetinvi and I can confirm that it is possible to upload a video in chunks with the upload api.
I do not know about Twitter4J apart for its name but you can do an upload by using multi-part webrequests divivded by chunks of up to 5MB.
You can read more about it here : dev.twitter.com/rest/public/uploading-media
The process is the following :
INIT (inform twitter that you want to upload a video/image
APPEND the binary (x times up to 15MB)
FINALIZE you query
In each of the steps, Twitter will return the media_id in the JSON. After the finalize you can use this media_id for 1 hour and use it as part of a tweet publication.
Cheers,
Linvi

I created a pull request to add this feature in twitter4j. You can look at the implementation here: Adding Chuncked, video upload. This supports async upload of large videos 512mb and 140 sec.

Related

How to download files over 6MB

I have the most basic problem ever. The user wants to export some data which is around 20-70k records and can take from 20-40 seconds to execute and the file can be around 5-15MB.
Currently my code is as such:
User clicks a button which makes an API call to a Java Lambda
AWS Lambda Handler calls a method to get the data from DB and generate excel file using Apache POI
Set Response Headers and send the file as XLSX in the response body
I am now faced with two bottlenecks:
API Gateway times out after 29 seconds; if file takes longer to
generate it will not work and user get 504 in the browser
Response from lambda can only be 6MB, if file is bigger the user will
get 413/502 in the browser
What should be my approach to just download A GENERATED RUNTIME file (not pre-built in s3) using AWS?
If you want to keep it simple (no additional queues or async processing) this is what I'd recommend to overcome the two limitations you describe:
Use the new AWS Lambda Endpoints. Since that option doesn't use the AWS API Gateway, you shouldn't be restricted to the 29-sec timeout (not 100% sure about this).
Write the file to S3, then get a temporary presigned URL to the file and return a redirect (HTTP 302) to the client. This way you won't be restricted to the 6MB response size.
Here are the possible options for you.
Use Javascript skills to rescue. Accept the request from browser/client and immediately respond from server that your file preparation is in progress. Meanwhile continue preparing the file in the background (sperate job). Using java script, keep polling the status of file using separate request. Once the file is ready return it back.
Smarter front-end clients use web-sockets to solve such problems.
In case DB query is the culprit, cache the data on server side, if possible, for you.
When your script takes more than 30s to run on your server then you implement queues, you can get help from this tutorial on how to implement queues using SQS or any other service.
https://mikecroft.io/2018/04/09/use-aws-lambda-to-send-to-sqs.html
Once you implement queues your timeout issue will be solved because now you are fetching your big data records in the background thread on your server.
Once the excel file is ready in the background then you have to save it in your s3 bucket or hard disk on your server and create a downloadable link for your user.
Once the download link is created you will send that to your user via email. In this case, you should have your user email.
So the summary is Apply queue -> send a mail with the downloadable file.
Instead of some sophisticated solution (though that would be interesting).
Inventory. You will split the Excel in portions of say 10 k rows. Calculate the number of docs.
For every Excel generation called you have a reduced work load.
Whether e-mail, page with links, using a queue you decide.
The advantage is staying below e-mail limits, response time-outs, denial of service.
(In Excel one could also create a master document, but I have no experience.)

Oracle Cloud MultiPartUpload using PreAuthenticated Request

I've been searching for hours and I could not find an answer to this: Can you upload files to Oracle Cloud's ObjectStorage using MultiPartUpload via a PreAutheticated Request? I know it's possible in just in one go.
I basically need to allow users to upload large files to Object Storage through a Java client and I would like to do it via PAR's. If it is possible, how would that happen? Meaning, do you call the CreateMultiPartUpload first and the upload the parts via the PAR? Do you call the CreateMultiPartUpload with the PAR?
It is not possible to use multipart uploads with a PAR today, unfortunately. We do hope to make this available very soon, though.
hope you are well!

API limitation Twitter

I'm new to API programming and I need some help.
I have a JAVA application that needs to use twitter API to send a request and get the response for specific data.
For example sending tweet ID and get video or image URL.
My question is that assuming the app will be used by 10,000 people daily with 1 Key for the API call, will there be any problem for my application to send and get the request from Twitter API?
I saw online that there are some limits for APIs calls, for example, your API key can't call more than 100 times daily, if so how it will work for my application if I have 1 key that will be used by 10,000 people from different location and countries.
Thanks in advance.

How to handle Blobs in Google App Engine alternatively to Cloud Storage and BlobStore API

The BlobStore API is marked as 'superseded' also limited to Limits to 32 MB.
The Google Cloud Storage is a vendor lock-in.
Is there a way to upload blobs with a 3rd part lib
In Google App Engine (not flexible / managed-vms) for example JClouds
And how would one bypass the 60 Seconds request limit that causes DeadlineExceededException?
To enhance the question;
Security is an issue, it would be preferably to run every request trough the application, so also blob uploads. Which makes the 60 seconds an issue.
The seperate uploadUrl is an option, but i do not wish to use BlobStore or Cloud Storage, but is there a generic way to handle things like this in GAE?
32MB is not a limitation of the BlobStore, but rather request playloads that go to your GAE app. You can upload larger files to both Cloud Storage and the BlobStore by creating a temporary URL for the user to submit the file to, which does not go through your ap, but rather goes directly to the storage service. You can find documentation about that for blobstore here. I don't personally use Cloud Storage, so I don't the a documentation link handy.
You can certainly use any other service in a similar way, but I'm afraid I can't explain how other than to say "consult their documentation". I know that's not a great answer to your question, but maybe insight into how it works with Google's products will help you understand how to use a 3rd party as well.
As for the 60 second request limit: since your upload requests cannot go through your server anyway, this is a non-issue. The 60 second limit only applies to requests made directly to your app.

Google App Engine + AWS S3 file protection!

I have an application running on GAE/J that streams video from AWS S3.
I need a solution for protecting the video from being stolen and I found that pre-signed URLs might be it (??).
How can I create pre-signed URLs from GAE/J or there's a better solution to secure the videos?
thanks
I need a solution for protecting the
video from being stolen and I found
that pre-signed URLs might be it (??).
What you're asking for is impossible. Pre-signed URLs will limit the availability of the file to a certain window of time, after which the link will stop working, but there's no way to allow someone to download something with a video player, but not store it to their computer.
Nick, that is not quite right. You can securely stream video with Amazons protected Flash rtmp video streaming service, using Cloudfront. Nobody will be able to download your files. There are tutorials about how to do it on the net. For instance here. You can also go straight to the cloudfront documentation. (Can't post the link here as I'm new to SO and can only post one link).

Categories