phoenix: show image from aws s3 - amazon-s3

I study the phoenix, create an application that loads the image on aws s3, and then displays it. I was able to upload the image to the cloud, but now it is not clear how to display it to the user on the page (I do not want to make public link to these images in the cloud). I was looking for information on this issue, but did not find anything useful.
From the clouds I get the file as binary data. Do I need to create some of these data is a temporary file that will be displayed on the page? I can display the image as base64, but I think this is not the best way. I would appreciate advice.

Since you've already fetched the image to a binary, you can just send it directly to the client with the appropriate content type and the browser will render it as an image. For example, to fetch and send the png at https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png:
def index(conn, _params) do
image = HTTPoison.get!("https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png").body
conn
|> put_resp_header("content-type", "image/png")
|> send_resp(200, image)
end
If you open this in your browser, you'll see the image being rendered correctly because of the content-type header.

Related

Android camera, take picture(s) and save as multipage PDF, then upload to server via <input type="file" />

I have a webform with and want to open it on smartphone - than take pictures of some documents which need to be merged in one PDF, and on the end this file need to be uploaded to server.
My solution is to use Google Drive to upload PDF (scan) to GDrive and then somehow download this file from gdrive to server via some sort of widget (any links appreciate) installed on website.
Maybe someone have a better idea?
I know its late but my answer might help others. I also face the same challenge and implemented a custom solution based on Javascript and Since you are using web form so this solution will perfectly fits on your need.
You have to use JSPdf javascript library, JSPdf provide you pdf object in your browser and you can upload it download it and there are many other thing to play with.
First you have to initialize JSPdf object as per your requirement. I am creating PDF with page size width:500px and height 500px.
pdf = new jsPDF("l", "pt", [500,500]);
Simply when you will take picture from camera you will have each picture in form of base64, that base64 format you have to insert in JSPdf object
pdf.addImage(imgData, 'JPEG', 0, 0);
you can repeat the above code to add pictures from camera as much as you want, at the back-end these images are compiling and creating pdf document where each page have each images in sequence.
Once you are done, you can get PDF object in form of base64 object using below code that you can upload to any server.
pdf.output('datauristring')
above is only pdf part, you can find complete working example including camera part here Javascript Component to Scan Document

How to upload custom image when create new channel

We need to have the ability to set a custom image for new channels.
From docs https://getstream.io/chat/docs/#initialize_channel, I can see the field image and if send here some remote URL - works fine.
But what to do when we need to send an image from the phone? For sending image for message I can see the functionality. But it's bonded to channel which is going to be created.
I know we can use base64, but I hope there is a better way of doing the required functionality? (like upload the image to server and get remoteURL)?

Why are the preview thumbnails blank when I try to share on LinkedIn?

I have an article on the website I help maintain, that I want to share on LinkedIn, via the "Share an update" form on the site. The possible thumbnail images are being detected, and LinkedIn is receiving the correct urls for the images in question (they are served from Amazon's S3 service).
Inspecting the page, I see that a call is made by the page to https://www.linkedin.com/sharing/api/url-preview and the JSON response includes a "previewImages" field (under "data"."content") which is an array of objects/dicts with the fields "url", "mediaProxyUrl", "width", "height", and "size".
The "url" of my preview images is correct. Copying and pasting into the address bar brings it up. The "mediaProxyUrl" however does not load an image. The "size" field is null.
Using a working reference url (an article on another site), I can see that "mediaProxyUrl" is supposed to be linkedin's url for the thumbnail, and that "size" is supposed to be the file size of the original image.
So, why are my preview thumbnails blank? Is this a problem on LinkedIn's end? Is Amazon s3 the problem? I'm at a loss.
P.S. I've checked my og:image and og:image:secure_url headers, they're in order.
Try setting image's Content-type property in S3.

How to save a photo location or actual photo as a class variable?

I have a class with a variable named Photo. The user is using the PhotoChooserTask to select the photo, and it is being displayed in an Image control. This part of the application, the chooser and display, works fine.
I would like to save either the location/path of the chosen photo or the actual photo so that it will be available for display into an Image control when the user ran the application later.
The whole class is saved using serialization, and I don't know how to save/serialize the photo (or the photo path) that way.
The photo should be still available to the user through the Camera Roll as well.
Any help, link or code, would be greatly appreciated.
If you're using a PhotoChooserTask you will will get a PhotoResult instance from the PhotoChooserTask.Completed event.
You can then PhotoResult.ChosenPhoto stream and save the content to a byte array (easy serialization) or a file in Isolated Storage.

How to upload photos using CakePHP 2.0

I'm developing a simple web app and I just want to allow the user to upload some pictures.
should I just store the picture url on my database table or should I upload the whole picture?
how can I validate the size of the picture being uploaded?
how can I upload the picture from my controller?
thank you all!
I would NOT store the image data in the database. I would create a Behavior that will upload the image to the image directory and store a reference to that image. The behavior can then handle size, mime type, etc. Then add a file upload form to the controller and when the data goes to the model to be saved, it will automatically upload the image and put it where it goes.
If you do not want to build your own, here is a very popular behavior that someone has built.
https://github.com/jrbasso/MeioUpload
Or you could try this simple way of doing it (check the readme.md file) :
https://github.com/malikov/cakephp2.0-image-upload