In my web app, I'm generating some large image files and would like the user to be able to export them using filepicker.io
My problem is that it seems I have to call filepicker.store to upload the generated file BEFORE I call filepicker.exportFile, but I want to upload the file AFTER the user has chosen a destination. Is this possible?
While not the most elegant mechanism, you can use the fact that filepicker urls are read/write to store a "temporary" image using the exportFile call. You can then take the FPFile object that is returned and do a filepicker.write() call to store the file after the destination has been chosen.
Related
I'm something new on the subject, excuse my ignorance. I am using IONIC, and in a moment I have to take a picture with my cell phone, then I have to save this photo. At the end of several screens and processes, I must upload my data to a post service including that image.
how can I persist that image in my application? I don't think it is possible to save a binary in the local storage of the cell phone, can I temporarily save it to a json and then send it as a formData?
Save the File object by angular service or global variable until your post service;
or
Upload pictures when you select them and save the filePath return by server; do your post service
I encountered a problem that when i upload an image , it takes a lot of time to upload it even if its only 1MB.
My Upload process is first use a <input type='file'> then convert the uploaded image to base64, convert it to byte then saving it to the database with image data type.
This is my SQL(Stored Proc):
IF EXISTS(SELECT * FROM VisitationLogs_BVL where UserIdx = #UserIdx and OutletIdx = #OutletIdx and convert(varchar, DateVisited, 23) = convert(varchar, getdate(), 23))
BEGIN
SELECT 0 'Result'
END
ELSE
BEGIN
INSERT INTO VisitationLogs_BVL(UserIdx,OutletIdx,CashierUser,IPAddress,Remarks,[Image])
VALUES(#UserIdx,#OutletIdx,#CashierUser,#IPAddress,#Remarks,#image)
SELECT ##ROWCOUNT Result, SCOPE_IDENTITY() AssignIdx
END
I will suggest you not to store the image in database. Instead you can save the image in your server and you can store the path of the image in database. Or else you can also use Azure Blob storage to save the image.
Storing images in the database is a big no because it uses alot of resources. and by converting the image to base64 you're using more resources, the best way to store images is to store them in a CDN like amazon s3 because then you're letting amazon take care of the whole upload process which won't put a toll on your database and your server. once you upload the image to s3 you can then get the url of it and just display it in your html. this is the most efficient way to store images using CDN will also ensure your images are cached across the world.
It is highly discouraged to store images in a SQL database as it will hugely reduce the performance. The recommended way is to store them as pure image files, store only the path in the database. Then use a simple http server to serve those static files.
More info: https://www.microsoft.com/en-us/research/publication/to-blob-or-not-to-blob-large-object-storage-in-a-database-or-a-filesystem
I'm trying to understand how tokens work in Firebase Storage.
Whenever my web app uploads an image to FS it adds a token to its public url. The problem is whenever you upload that same image file to another part of the web app, it seems like you don't get another file, but a different token for the file url that was already uploaded, thus rendering a 403 error for the previous registered image display.
Is there a way to solve this?
Example:
storageRef.put(picture.jpg);
uploadTask.snapshot.downloadURL
// returns something like https://firebasestorage.googleapis.com/v0/b/<your-app>/o/picture.jpg?alt=media&token=09cb2927-4706-4e36-95ae-2515c68b0d6e
That url is then displayed somewhere inside an img src.
<img src="https://firebasestorage.googleapis.com/v0/b/<your-app>/o/picture.jpg?alt=media&token=09cb2927-4706-4e36-95ae-2515c68b0d6e">
If the user repeats the process and uploads the same picture.jpg in another section of the app, instead of getting a brand new copy in Firebase Storage, the file is overwritten with an URL ending with a new token; say 12345.
So:
<img src="https://...picture.jpg?alt=media&token=12345"> // New upload renders fine
<img src="https://...picture.jpg?alt=media&token=09cb2927-4706..."> // But old upload breaks because of wrong url
Tokens are unique for a particular version of an upload. If you overwrite the file with new content, then a new token will be generated with a new unguessable url.
So in other words, tokens are unique for a particular blob -- they are not unique per storage location. We did this as an increased measure of security to ensure that developers and end users did not accidentally expose data they did not intend.
You can, however, translate the storage location ("gs://mybucket/myfile.png") into a download url using our js SDK. That way, you can pass around the gs uri if you wish and translate it to a full URL once you want to place it into an image.
See: https://firebase.google.com/docs/reference/js/firebase.storage.Reference.html#getDownloadURL
For public file upload: If you upload files in firebase functions you'll need to call makePublic() on the reference object in order to make it accessible without having a valid token.
What is the proper way to upload images into a MySQL database?
Generally, I declare the 'image' field as text and I use move_uploaded_file() function in order to save images on my server.
Is this the correct way to upload images into a database? I will have to upload lot of images, as social networking website might have to, for instance.
I think there are two reliable ways to work with images into your database:
1 - Store the file in some folder at your server, then write the filepath in some field in your image table.
2 - Encode your image as base64 with the base64_encode($yourImageData) method. This method will return a string that can be inserted into your table.
Preferably upload the image to server using File handling and PHP image libraries like GD and then store path as string in database. I think that should work.
As pointed out, it is not a good idea to save the image directly into database compared to save image on filesystem then save path/link to table fields.
but since the question is "upload images into mysql database"
I think you can check http://www.mysqltutorial.org/php-mysql-blob/
Here's what my file picker looks like
filepicker.pick({
mimetypes: ['image/*'],
services: ['COMPUTER', 'URL'],
maxSize: 5 * 1000 * 1024
}, function(FPFile) {
// do stuff to file
});
The problem is that when a url select is chosen, instead of uploading the file to file picker the url is served directly. This makes storage unreliable because the external host can take the file down, etc.
Is there a simple way to ensure that when using the URL upload the file is directly hosted?
There are two options for this.
The first of which is the Store API. When you receive the fpurl back, call the store api and this will save the file to your storage directly. This might be best if, for example, people can select files at will, but you only want to persist them when they choose to save something. e.g. when uploading for a new post. Why persist items if they don't decide to create a new post in the end?
https://developers.filepicker.io/docs/web/#store
The second option is to replace your pick call, with the pickAndStore call, which does both at once and saves you having to do the store command in your pick callback.
https://developers.filepicker.io/docs/web/#pickAndStore
While pickAndStore may feel like it saves work, if there's a chance that you don't actualy need to persist data after a user picks it, then I'd go the extra distance with your own custom callbacks (this is where you'd create difference conversions too).
The best way is to use the filepicker.store api - see https://developers.filepicker.io/docs/web/#store for more information