how to use TwitterAPI v1.1 to upload an image in s3? - laravel

I am developing web app using laravel and s3
I just wanna upload an image to twitter server like this https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload
why I cannot upload and how can I solve this.
Thank you.
I am absolutely sure that there is the image in s3 to see
dd($result['ObjectURL']);
I've tried these
$twitter = new TwitterOAuth(
'consumer_key',
'consumer_secret',
'access_token',
'access_secret',
);
$s3FilePath is like "https://buket_name.s3・・・"
$media = $twitter->upload('media/upload',['media' => $s3FilePath]);
//could not upload."You must supply a readable file"

Related

How to upload image to Google Drive using MIT APP Inventor II

I'm trying to upload selected image by MIT App Inventor II. What I did is to download an extension which encodes image to base64 coding, and then call Web1 to address Google App Script. Actually, what I did is just follow an YouTube channel, but somehow it does not work.
function doPost(e) {
var data = Utilities.base64Decode(e.parameters.data);
var blob = Utilities.newBlob(data,e.parameters.mimetype,e.parameters.filename);
var folderid = Utilities.base64Decode(e.parameters.folderid);
DriveApp.getFileById(folderid).createFile(blob);
return ContentService.createTextOutput("Your File Successfuly Uploaded");
}
Combining with Taifun's Extension. These blocks are confirmed to be able to do as below.
Display the ImagePicker selected image on the Image component
Encode the ImagePicker selected image to a Base64 string.
Send the string to URL (Google App Script)

Upload Facebook profile image with Carrierwave

I'm trying to use the Facebook profile image with Devise, uploading it to S3 with CarrierWave / fog, but the link I'm getting from Facebook provided in auth.info.image is a link to download the file, not an image that CarrierWave can use.
If you go to the link in a browser, it is a file download link. I've not seen any articles anywhere that address this. I thought I could use CarrierWave to download the file to /tmp, then upload it, but calls to CarrierWave::Uploader::Download do not work. Or I've seen other articles explaining that you can save the link provided by Facebook just use that in an = image_tag but that doesn't work, either.
In my User model:
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create! do |user|
user.email = auth.info.email
user.provider = auth.provider
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.uid = auth.uid
user.password = Devise.friendly_token[0, 20]
user.password_confirmation = user.password
user.profile_image = auth.info.image
end
end
but user.profile_image is nil. I have no problem with CarrierWave - I've used it on several other projects to save to AWS with fog.
I would like to either a) save a link to the image that I can use in a Rails view, but as mentioned already, I do not have that - the link returned by Facebook is a link to download an image, so, b) is to download the file, save the filename to the User model and upload the file to AWS.
Use "#{auth.info.image}?type=large" instead of auth.info.image
Apparently CarrierWave has its own magic, whereby if you prepend the field name with remote_ and append it with _url it knows to download a file before uploading. So, my field name is profile_image, and (in my User model) self.from_omniauth(auth) method:
user.remote_profile_image_url = auth.info.image
just works. The field name has the correct filename saved to it, and the files (full size and thumbnail) are uploaded to S3.

Saving Images Using Spring Boot and MySQL

I am creating a web app using Spring Boot and JPA. I want to upload many images. I want those images to save in a storage and save the location of the file into database. I am not understanding how to achieve this?
After researching a lot, I have come to a solution. I have used Amazon AWS S3 for storing the media data. Amazon AWS S3 comes with its own library. It gives you rich api to upload the media files and having control over them. I have just uploaded the file into the S3 Bucket and saved the corresponding URL into the MYSQL database. Please comment if you need the corresponding codes.
I have encountered this problem in Django application.
What i did was just used amazon S3 bucket and store all the images. I get the location of the image which is in s3 and store it in mysql DB. when i need the image i just call the image from s3 and used it.
Accept Images as a zipstream(Faster)/binarystream or as a MultipartFile
Load the stream ZipInputStream zis = new ZipInputStream(inputStream);
load the stream to File using Java.IO.File class
Push the file data to file system(Same server machine or any non-sql Database)
save the Location in a DB using Spring data JPA
This is how I DID it.
I store my images as a LONGBLOB in my MySQL database so use columnDefinition = "LONGBLOB". In your HTML code for your upload button, make sure you include the multiple = "true" in your tag if you are using HTML.
In your Controller class make a multipart file that will get the images if you are using binding models and also, you need to have a Set/List of images so you can go through them all.
MultipartFile[] images = bindingModel.getImages();
Set<Image> newImages = new HashSet<>();
I have this neat for loop so I can go through all of my images:
for (MultipartFile multipartFileFOREACH : images)
{
Image newImage = new Image(multipartFileFOREACH.getBytes(), postEntity);//Image is an Entity here, postEntity is an object
newImages.add(newImage);
this.imageRepository.saveAndFlush(newImage);
}
this.articleRepository.saveAndFlush(articleEntity);
So, here I store my bytes into the LONGBLOB in the SQL database
Then for the actual view
Set<Image> imagesBytes = post.getImages();
List<String> images = new ArrayList<>();
for (Image image : imagesBytes)
{
images.add(Base64.getEncoder().encodeToString(image.getLink()));
}
My Image Entity has a link variable of type byte[]
Then I simply add the view for the HTML:
model.addAttribute("images", images);
use s3 bucket for storing image and my sql for storing the address of the image
Using MultipartFile you can upload the file.
Save the File in your server using Files.Copy through BufferedInputStream
Save the saved-location of your file in your database through Spring-Data repository.
There are three options to store your files.
a) in your local file system
b) store in db as bytes
c) use cloud service such as AWS S3 bucket
This is a good tutorial for setting up S3 bucket with SpringBoot applications.
https://medium.com/oril/uploading-files-to-aws-s3-bucket-using-spring-boot-483fcb6f8646

File should upload outside the root folder

Im using codeigniter framework,
I have two folders in my public html folder,one contains the main website and other have mobile website
Both having same database
The issue that im facing is,
i want to upload a file from mobile website which should be uploaded in the folder which can be accessible for both sites(mobile and main).
While uploading from mobile site ,it only uploading inside the mobile folder(mobile site)
Some one please tell me how can i upload the file outside the mobile folder(mobile web root),im really struggling in it.
Fileshould upload outside the root folder
Give below is the code i am using
if($_FILES["resumecar"]["name"]){
$file = basename($_FILES['resumecar']['name']);
$ext = end(explode('.', $file));
$ext = strtolower($ext);
$filename = "resume_".time().'.'.$ext;
move_uploaded_file($_FILES["resumecar"]["tmp_name"],"uploads/careers/".$filename);
$uploadfile = "uploads/careers/".$filename;
}else{$filename = '';}

Attach image using Twitter Share link

Is it possible to attach an image to a tweet using the Twitter share link?
I'm using the following url to tweet but I can't find away to attach an image. The tweet has a link to the image but I want it attached to the tweet so someone can view the image while reading the tweet.
https://twitter.com/intent/tweet?hashtags=MyTag&url=http%3A%2F%2Ftest.com%2Fimage.png
Or would have to use the twitter api?
I would recommend using https://tweetinvi.codeplex.com/documentation which you can programmer directly with twitter.
// Publish with media
byte[] file = File.ReadAllBytes(filePath);
var tweet = Tweet.CreateTweetWithMedia("I love tweetinvi", file);
var imageURL = tweet.Entities.Medias.First().MediaURL;
// Publish with geo information
var tweet = Tweet.CreateTweet("Hello guys");
tweet.PublishWithGeo(-54.73, -64.2);
// Retweet
tweet.PublishRetweet();
I do not believe it is possible to upload media through the share link. Probably, a security decision by Twitter.
I suggest you try the twitpic API.

Resources