Upload Multiple Images to API using Multi Image Picker - flutter

I am attempting to implement the ability to upload multiple images (along with some other data) to an API using data entered via a form on my flutter application.
I am using https://pub.dev/packages/multi_image_picker which stores all the images as a List<Asset>
The API I am attempting to connect with says it requires the following fields.
firstname, lastname and images[].
I have started to encode the json body using:
var body = json.encode({"firstname": firstNameField, "lastname": lastNameField, "images": imageList});
but this failed. Does anyone have any suggestions?

Hey #Bollie, You can do using the flutter_uploader package, it's very simple you can post your data in formdata separately with multiple files/images.
here is more info on how you can do,Hope it'll work for you.. https://github.com/BlueChilli/flutter_uploader/issues/9
feel free to ask any questions regarding this, Actually I recently did it so...

Related

Get Firebase Dynamic Link Data from String Input url Flutter

Dynamic links work great for 98% of our users. However, there are still a group of users which have difficulty with them or do not know how to use them.
I want to add a feature which would let users paste their link into the app, and then we extract the data from the link and handle it normally. This will also serve as a backup for when the links are down or misbehaving. It will also allow our customer service team to get data from a link when customers share them with us.
The problem is, there doesn't seem to be a way to manually pass in a dynamic link to retrieve the dynamic data.
Does anyone know how this can be achieved?
Here is my attempt at your question.
I am assuming what you mean by the dynamic data is the underlying deeplink along with the parameters associated with the deeplink.
void dynamicLinkToDeepLink(String dynamicLinkString) async {
final details = await FirebaseDynamicLinks.instance.getDynamicLink(Uri.parse(dynamicLinkString));
// your deep link can be accessed as follows
details!.link;
}
You have to safeguard the above code as you see fits when you use it. You will have to wrap FirebaseDynamicLinks.instance..... with a try catch block and you will also have to check if the value of the returned link is not null before acccessing details!.link

Create simple product in magento 2 and add full url images?

sorry for my english.
I have a store in Magento 2, and when the user search for some product that not exist in my db, i send a request to a external api that return a list of 10 products, so my idea is create these products on the fly using the m2 api and send 10 request in parallel, the problem is the images, if i have to download each images for each product and convert to base64 to then upload in other request, the performance is too bad.
Is there the possibility to in the same request (mysqite.com/rest/V1/products) create the products and add the full url image to each one?

Upload JSON Request as a background task in Flutter

I have a requirement where I want to upload JSON request data(fetch from database tables) to server and get the response, based on response I have to update local database(sqflite: ^1.2.1).
I have multiple screens and I need to create different JSON request data on every screen based on user action. Currently for same scenario I am using Intent Service in my another native android application.
What is the based way to handle such type of scenario in flutter Android application. If I use channel and implement Intent Service then I can't access sqflite database in Android specific region. If internet is not available then I have to keep waiting for connectivity, when device get connectivity then I need to upload all the created events to server one by one.
Please someone advise me the based possible way to handle this specific scenario in Flutter.
Thanks in advance
Save your JSON requests locally first using sqflite or sharedPreferences for instance. Once they are synced to your served, remove them from sync queue
I got the solution: I am able to access SQFlite database in native through channel.
This is the path of the database created in flutter
"/data/data/{package name}/app_flutter/{database file name}"
So we can access like in native using channel
SQLiteDatabase mDatabase= SQLiteDatabase.openDatabase("/data/data/{package name}/app_flutter/{database file name}", null, 0);
Log.i("MainActivity", "mDatabase.isOpen():"+mDatabase.isOpen());//check DB is open or not
String query = "SELECT * FROM {Table Name}";
Cursor cursor=mDatabase.rawQuery(query,null);
if (cursor.moveToFirst()){
do{
String data= cursor.getString(cursor.getColumnIndex({Table Column Name}));
Log.i("MainActivity", "Column Data Value:"+data);
}while(cursor.moveToNext());
}
cursor.close();
So I will implement Service in native to achieve this scenario.
Thank You

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.

Using Restkit and Core data to Retrieve Images

I have a core data application using rest kit to retrieve data from a web service. The response i get from the webservice is a json string like this -
"nodeRef": "workspace:\/\/SpacesStore\/b1d51831-990d-47a8-a018-f1c1bg33f594",
"type": "document",
"name": "x.jpg",
"displayName": "x.jpg",
"title": "myTestProject",
(This is some meta data around an image. If i want to retrieve this image then i should access it using this url - http://x.co.uk/share/proxy/alfresco/api/node/workspace/SpacesStore/b1d51831-990d-47a8-a018-f1c1bg33f594/content/thumbnails/ipad1024?c=force) - note ive changed the URL slightly so you wont be able to access it. Also you need to authentication to access the URL. So i was wondering how i would go about getting this image and storing it locally on my SQLite DB? I can obviously access the URL but how exactly do i prompt it to download the image
What i did in this situation was to do a lazy load on the image with something like:
image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.absoluteUri]]];
NSData *imageData=UIImageJPEGRepresentation(image, JPGCompression);
Then store it. Outside of Restkit. This was a while ago, but it worked for me.
Basically extract the URL from restkit, do a lazy load when the image is presented on the screen, and thne store it back to core data (or wherever) when you have loaded it once.
Hope this helps.