Load and save images on Flutter - flutter

I Want to let the user chose images from his gallery and add them to the app, and i want the image to be saved on the local app storage, so should i create a Database for saving the pictures or just for saving the path to those pictures (refrence)

It's up to you if you want to manage the references in a database, depending on your needs.
If you need to store plain pictures without anymore linked informations I would just go for path_provider's application Directory, as the example tells (https://pub.dev/packages/path_provider):
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
And then just use the whole directory.
If you need to store more meta data, as e.g. like count of a picture or some origin url etc. then i would go for a sqlite database storing the references and meta data in a table.

Related

How to remove query string from Firebase Storage download URL

Problem:
I need to be able to remove all link decoration from the download URL that is generated for images in Firebase Storage.
However, when all link decoration is stripped away, the resulting link currently would return a JSON document of the image's metadata.
Context:
The flow goes as follows:
An image is uploaded to Firebase from an iOS app. Once that is done the download URL is then sent in a POST request to an external server.
The server that the URL is being sent to doesn't accept link decoration when submitting image URLs.
Goal:
Alter the Firebase Storage download URL such as it is stripped of all link decoration like so:
https://firebasestorage.googleapis.com/v0/b/example.appspot.com/o/[FOLDER_NAME]%[IMAGE_NAME].jpg
Notes:
The problem is twofold really, first the link needs to be manipulated to remove all the link decoration. Then the behavior of the link needs to changed, since in order to return an image, you need ?alt=media following the file extension, in this case .jpg. Currently, without link decoration, using the link with my desired structure would return a JSON document of the metadata.
The current link structure is as follows:
https://firebasestorage.googleapis.com/v0/b/example.appspot.com/o/[FOLDER_NAME]%[IMAGE_NAME].jpg?alt=media&token=[TOKEN]
Desired link structure:
https://firebasestorage.googleapis.com/v0/b/example.appspot.com/o/[FOLDER_NAME]%[IMAGE_NAME].jpg
The token is necessary for accessing the image depending security rules in place, but can be ignored with the proper read permissions. I can adjust the rules as needed, but I still need to be able to remove the ?alt=media and still return an image.
Building up on Frank's answer, if you access to your associated Google Cloud Platform project, find the bucket in the Storage tab and make this bucket public, you will be able to get the image from here with the format you wish. That is, you will not be accessing through Firebase
https://firebasestorage.googleapis.com/v0/b/example.appspot.com/o/[FOLDER_NAME]%[IMAGE_NAME].jpg
but through Google Cloud Storage, with a link like
https://storage.googleapis.com/[bucket_name]/[path_to_image]
Once in your GCP project Console, access the Storage bucket with the same name as the one you have in your Firebase project. They are the same bucket. Then make the bucket public by following these steps. After that, you will be able to construct your links as mentioned above and they will be accessible with no token and no alt=media param. If you do not want to make the public to everyone, you will be able to play around with the permissions there as you wish.
You could split the url string into two halves by using String.componentsSeparatedByString(_ separator:)
Storage.storage().reference().child(filePath).downloadURL(completion: { (url, error) in
let urlString = url.absoluteString
let urlStringWithoutQueryString = urlString.componentsSeparatedByString("?").first!
})
Calling .downloadURL on a StorageReference will return you that URL, but this method can be used to remove the query string from any URL. String.componentsSeparatedByString(_ separator:) breaks a String into an array of Strings, splitting the string by any occurrence of a given separator, in this case ?.
NOTE this method assumes that ? occurs only once within the url string, which I believe is the case for all Firebase Storage urls.
You should treat the download URL that you get back from Firebase as an opaque string. There's no way to strip the parameters from a download URL without breaking that download URL.
If you want to allow public access to the files in your bucket with simpler URLs, consider making the object in your (or even your entire) bucket public.

How to implement Captioning in Azure Media services V3?

How to complete captioning in azure media service 3by using .net SDK
I am using Azure Media Services v3 tutorials (https://github.com/Azure-Samples/media-services-v3-dotnet-tutorials) but missing How to update a video caption file(vtt file) into a media service asset by using .net SDK. Can some body help me on same.
You would simply treat the caption file the same way as you would a video that you upload. The only difference is that the caption file would be put into an asset that already has video. In other words, you'd upload your video, encode it, and in the output asset you'd upload the VTT file.
From a code perspective you would use:
// Use Media Services API to get back a response that contains
// SAS URL for the Asset container into which to upload blobs.
// That is where you would specify read-write permissions
// and the exparation time for the SAS URL.
var response = await client.Assets.ListContainerSasAsync(
resourceGroupName,
accountName,
assetName,
permissions: AssetContainerPermission.ReadWrite,
expiryTime: DateTime.UtcNow.AddHours(4).ToUniversalTime());
var sasUri = new Uri(response.AssetContainerSasUrls.First());
// Use Storage API to get a reference to the Asset container
// that was created by calling Asset's CreateOrUpdate method.
CloudBlobContainer container = new CloudBlobContainer(sasUri);
var blob = container.GetBlockBlobReference(Path.GetFileName(fileToUpload));
// Use Strorage API to upload the file into the container in storage.
await blob.UploadFromFileAsync(fileToUpload);
Where assetName is the name of your output asset.
How were you planning to deliver captions for playback? For the example in the Azure Media Player, the VTT file is added as a separate URL (from the HLS or DASH streaming URL). If this works, then you can simply edit the streaming URL and add the file name of the VTT file (as shown in one of the examples in the player page).
If, however, you need playback of captions via other HLS or DASH players, then there are some additional steps needed to expose the captions track along with video and audio. We will update our documentation pages when certain service updates have been deployed.

How to save sign up api response and pass the data in the response to profile screen

In my app how do i save signup API response i.e userid,username,email,profile image and once sign up successfully it takes me to profile screen . How do i show the saved response in the respective field in profile screen controller. I am using alamofire for parsing and have also created signup data model. How can i save with swifty user defaults library
You can use Database (Core Data, Realm, ...) or UserDefaults to store data.
You can use userdefaults for saving your username,userid,username,email. If you have profile image as url string, you can save it in userdefaults and call it on image in your profile screen too. If you have profile image as an image, may be you can cache it or save it in a singleton class. Storing process can be multiple so you have to choose it depending your business of app.

Filepicker s3 custom folder under bucket

We are trying to use Filepicker.io to upload our user submitted photos to S3. But looks like filepicker does not allow uploading to custom folders within one bucket.
What we have is the following structure.
Bucket_Name/category/username/file.jpg
Usernames are done by each user on our site.
Why is this not allowed?
Thank You
You'll want to make use of the path parameter on the filepicker.store() call (https://developers.filepicker.io/docs/web/#store):
filepicker.store(input, {path: 'category/username/file.jpg'},
function(new_fpfile){
console.log(JSON.stringify(new_fpfile));
}
);

Fetching Contact image from SugarCRM

I'm trying to integrate my rails app with SugarCRM. Is it possible to fetch the Contact picture from SugarCRM using REST API? Please let me know.
To get the profile image for a user do the following:
Call the login method through REST
Call the get_entry_list method through REST, with the following parameters:
Module: Users
Query: users.user_name = 'xxxx'
Select_fields: picture
The response contains the filename for the profile image, which is stored in /uploads.
However, it is not possible to view the image in that folder due to .htaccess restrictions for security reasons, but other options exist:
Extend the REST API with a method to serve profile images (similar to get_document_revision)
Login on the server from your rails app and get the image
Create a simple entrypoint+module in SugarCRM, which can show the picture
Remove the .htaccess restiction for images (if it doesn't create a security risk in your setup)
In such scenario, I faced a problem where the upload folder stores file with name of the record id, i.e the GUID without file extension.
So to cop up with this I did write a function to copy the file at same hierarchy but with its extension.
Example:
A png extension file at upload folder with name say, '32sdft-tg35f-Tuhis-675rtyf-77666-46dgc' will end up as, '32sdft-tg35f-Tuhis-675rtyf-77666-46dgc.png'
Now only the path will be require to render the image.
Rest all things as applicable as suggested by our friend, Kare !!