I have a firebase function which given some arguments creates a "post" with a title and the such. Is there a way to send an image as an argument which can then be processed by firebase functions and then upload to firebase storage.
I think it is possible by decoding the file/image object to a base64 string which could be then sent as an argument. How would I convert the file object from html file input to base64? On the other side how would firebase functions know that the string is an actual image? How can I tell the size of the image? Is there a limit to the size of arguments given to a firebase callable function?
I ditched this question but came across the problem later in a different project. So to anyone seeing it is possible through base 64 strings. It has the restraints that the image cannot be bigger than 10mb but it is easier than trying to "catch" the file after it being uploaded directly.
Here is the solution
I would do the following:
Let the user upload the file directly into firebase storage in a folder where only the user has access to.
Let a function trigger on upload that takes this image, checks if the user is authorized to put that in the target folder and put the file in there (or whatever you want the function to do exactly).
Related
I want to store data (increasing everytime the extension is "triggered") in a json file to display it for the user. I can't find a solution on how to add a json file where I can store and overwrite data.
To store persistent data between between uses, you'll need to use the "storage" API which you can read about here.
Basically, you'll want to include the storage API in your manifest, then call it with methods like let gettingAllStorageItems = browser.storage.local.get(null);. Here's an example.
I have some images (jpg, png) uploaded to aws s3 bucket. I want to extract some informations (lambda is written in golang) from the image (width and height). Is it possible to do this without downloading the image?
You can do a partial download of the object using the range header
See this SO answer S3: How to do a partial read / seek without downloading the complete file?
in the AWS go sdk func (Downloader) DownloadWithContext seems like it should provide range feature
Once you have the partial file it may be possible to extract the size information, see this answer What is the header size of png, jpg/jpeg, bmp, gif and other common graphics format?
S3 will not calculate dimensions for you. You calculate them beforehand.
You can use user-defined meta tags. You can set them when you send the object, or update them after they exist.
For private objects, the API must return user-defined meta tags.
For public objects, you can use the traditional GET verb or just the http HEAD verb in the object's public url.
Even javascript + ajax can read this header information.
My question is quite simple but I can't find any clear reference : I'm building a webservice that returns gameboard informations (in json for unity) and the image of the game.
Should I, in my informations include a field "image" with my image in base64 ?
Or in my information include a field "image" with the exposed url of the image (on my server still), and then do a second call to get the image ?
Which is the best practice toward unity android/ios ?
OK, i will prefer to use first option.Your information include image field.As http works with TCP it will deliver 100% and i think there is no need for second call to get game image
In my experience, use the second method avoid downloading the same image every time when I call the webservice.
I just check the image if exist in persistent data directory of my device. Don't need to download the resource again until the url content changed.
Saving the image in a web directory and storing the URL in the database using this approach, I stored the image URL in the database. Based on that image id (I need to pass this image id to the controller from an Ajax call). I need to retrieve the image.
I got the image id using a jQuery template, so I have passed that image id to the controller. What should I write in the controller, filepathresult or fileresult? Or is there another approach?
OK, you're a bit confused.
You have the actual image file, file.jpg and you have the physical path to the file, D:\some\path\to\file.jpg.
You have the URL path to the file and a surrogate identity (your id).
id: 1337 (some random number)
URL: ????
First question:
You say you're storing the URL. Is it really the complete URL? Is it just a partial path to the image? Is the path from the root of the website or the root of the application? Is it just a partial physical path?
Second question:
What are you actually trying to do?
Do you just want to get the full path to the image? Why do you need Ajax to do this, if you already have the id? You might want to rethink how you're storing the images if any performance needs to come out of this.
Once an image gets a new identity, it often makes sense to use that new identity everywhere; you might ought to consider copy/rename the file for the new identity after it's uploaded (and possibly save the old filename for record keeping purposes). If you need to keep the file names (more or less) as-is, however, it'd be better to provide the ability to grab the URLs for a whole set of ids rather than to individually make an Ajax request id-by-id.
If you request a resource (AKA navigate to a URL) that has a physical file, IIS is going to serve it directly (that is, if you ask for www.mysite.com/Images/Image3.jpg IIS is going to serve it directly). I really don't understand exactly what you are doing, but if you mean that you get the associated URL for an image using an Ajax call to an MVC controller with the id of the image, you could do several things.
You could simply return the URL and use JavaScript code to create an image tag with that URL and inserting it in the DOM.
You could return a view like <img src="{yoururl}" /> and insert it in the DOM using JavaScript.
You could store the images on the database directly and use the File method to return the image bits indicating the correct MIME type.
I'm using Spring 3 ability to upload a file. I would like to know the best way to validate that a file is of a certain type, specifically a csv file. I'm rather sure that checking the extension is useless and currently I am checking the content type of the file that is uploaded. I just ensure that it is of type "text/csv". And just to clarify this is a file uploaded by the client meaning I have no control of its origins.
I'm curious how Spring/the browser determines what the content type is? Is this the best/safest way to determine what kind of file has been uploaded? Can I ever be 100% certain?
UPDATE: Again I'm not wondering how to determine what the content type is of a file but how the content type gets determined. How does spring/the browser know that the content type is a "text/csv" based on the file uploaded?
You can use
org.springframework.web.multipart.commons.CommonsMultipartFile object.
it hasgetContentType(); method.
Look at the following example http://www.ioncannon.net/programming/975/spring-3-file-upload-example/
you can just add the simple test on CommonsMultipartFile object and redirect to error page if it the content type is incorrect.
So you can also count the number of commas in the file per line.There should normally be the same amount of commas on each line of the file for it to be a valid CSV file.
Why you don't just take the file name in you validator and split it, the file type is fileName.split("\.")[filename.length()-1] string
Ok, in this case i suggest you to use the Csvreader java library. You just have to check your csvreader object and that's all.
As far as I'm aware the getContentType(String) method gets its value from whatever the user agent tells it - so you're right to be wary as this can easily be spoofed.
For binary files you could check the magic number or use a library, such as mime-util or jMimeMagic. There's also Files.probeContentType(String) since Java 7 but it only works with files on disk and bugs have been reported on some OSes.