Reading a post request with image file, and convert in base64 encoding string - image

I wanted to ask how can we read a post request of a form that has file upload and then convert the file in base64 encoded form.
Looked at the examples shown in the play framework site, but it only explains about uploading a file and storing it in some location. But what if I need to convert the uploaded image into a base64 encoded form??
I looked through various resources, could not find what I was looking for. I just have a simple form that uploads image and need convert the upload image to base64 encoding. And yes I am using play framework.
Any help, please.
Update:
What I was actually searching for was:
val imageRaw:Option[play.api.mvc.MultipartFormData.FilePart[play.api.libs.Files.TemporaryFile]] = request.body.file("picture").map { picture =>
picture
}
Now how do I convert the imageRaw to base64 encoded string, I don't need to store the image in the disk.
Update2:
What I really had to achieve was load an image using drag and drop functionality and then load the image in a HTML5 canvas, had no problems with other browsers but since IE9 doesn't support FileReader Api, I couldn't retrieve its imageData after its loaded using the DnD functionality.
So, now I am trying to use polyfills to be able to use FileReader API in IE9, does anyone have any idea or samples of how to use them. I have been trying to use FileReader API for now, but can't get to know how to use it.

Related

Is that possible to embed a Blob URL image in markdown?

I want to embed a Blob URL image in my Github README.md file. When I tried ![image](blob:https://{...}) it failed. Is that possible to embed this format in markdown file?
Unfortunately github doesnt allow either blob or data uri's as image source.
source : https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#images

MigraDoc - How to Add image from External URL

I am not able to add image that is saved at a URL something like "http://host/img.png" using below code snippet:
section.AddImage(url);
However if I use url as a relative url of image that is present on my disk then this is working fine.
Is this limitation of MigraDoc?
Can someone provide workaround, code samples to over come this?
MigraDoc works with local files (relative or absolute paths), not with files that are somewhere on the Internet.
AddImage() needs a path, not a URL.
You can download the image from the URL and either store it in a local file or store it in a string using BASE64 encoding and pass that string to MigraDoc.
You will have control over accessing the image from the web and can properly deal with problems.
See this article on BASE64 encoding for MigraDoc images:
http://pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx

Store and use images locally

I'm quite new to addons development on Firefox.
I need to store an image from a given url, and then get the path to upload on another web. I read the Mozilla docs but can't figure how to do this.
I appreciate any help.
This does exactly what you need: How to download image to desktop with OS.File - you download the image with XHR, you then write that data to anywhere you want with OS.File.writeAtomic Instead of that XHR function, because you are using the SDK you should use the request module - https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/request

why does web server display images corrupterd?

I have a page in JSP, which has a tag like:
<img src="images/1.bmp"></img>
The 1.bmp is like:
But the image which looks in my page, visited by firefox, is like:
what should i do to fix this problem?
I've converted the images which you uploaded into your question back to BMP and investigated their source. Everywhere where a non-ISO-8859-1 character appears in the original source, a ? appears in the malformed source.
This means that you've a servlet on /images/* which uses response.getWriter() to write the image using the platform default charset. You shouldn't do that. BMP files are not text files. BMP files are binary files. You should be using response.getOutputStream() to write binary data. You can find a basic and proper example of an image servlet in this article.

How do I bulkupload image BLOBs in Google App Engine?

I have a model which *I want* to contain an image blob. I have the images on my local filesystem, but due to the nature of my application, I need to get them in the datastore. Here's my model:
class JeanImage(db.Model):
type = db.StringProperty(required=True, choices=set(["main","front","back","detail"]))
image = db.BlobProperty(required=True)
I haven't tried anything yet because I'm not great when dealing with images.
How can/should I convert my images to blobs so that I can get them in my bulkupload csv file?
Mark
You can do it, just not with the bulk uploader. You need to access the remote api directly.
This site has a basic example of how to use it:
http://www.billkatz.com/2009/2/Remote-API-Hello-World
Its pretty slow and a good idea to have a retry mechanism.
A more detailed description can be found here:
http://code.google.com/appengine/articles/remote_api.html
I believe that what you are trying to achieve is not possible using the app engine bulkloader.
Instead try to create some kind of uploader yourself. For example you could upload the images as a zip file and then extract it an store it in the datastore. The code for that should be fairly straightforward if you can map your images to the datastore entity (e.g. by using a naming convention).

Resources