Closed LuchoTurtle closed 1 year ago
I keep getting this annoying error when trying to make the request from the web :(
The platformViewRegistry getter is deprecated and will be removed in a future release. Please import it from `dart:ui_web` instead.
Restarted application in 296ms.
Error: XMLHttpRequest error.
Did you open a stackoverflow question for this? There are a few people hunting for Dart/Flutter points who will help. 🤞🏼
JUST got it working with a combination of using http.Client()
and adding a proper contentType
.
final request = http.MultipartRequest('POST', Uri.parse(apiURL));
final httpImage = http.MultipartFile.fromBytes('image', bytes,
contentType: MediaType.parse(lookupMimeType('', headerBytes: bytes)!), filename: platformFile.name);
request.files.add(httpImage);
// Check the response and handle accordingly
return http.Client().send(request)
Which is weird since the console was giving off CORS errors. I was trying to add the proper headers but it wasn't working. But this did, so I think it might be the way with hhow the bytes were being parsed and being added to the request.
I'm adding this to the documentation.
Urgh. It seems to be working but now I'm trying to get this to run on a real iPhone and I'm getting:
[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
* thread #35, queue = 'com.apple.root.default-qos', stop reason = signal SIGABRT
frame #0: 0x00000001e8e72bc4 libsystem_kernel.dylib`__abort_with_payload + 8
libsystem_kernel.dylib`:
-> 0x1e8e72bc4 <+8>: b.lo 0x1e8e72be4 ; <+40>
0x1e8e72bc8 <+12>: pacibsp
0x1e8e72bcc <+16>: stp x29, x30, [sp, #-0x10]!
0x1e8e72bd0 <+20>: mov x29, sp
Target 0: (Runner) stopped.
Lost connection to device.
Even though I've added these to the Info.plist
file.
<!-- Required to access photos -->
<key>NSPhotoLibraryAddUsageDescription</key>
<string>We need add only access to save medias</string>
<!-- Required to access photos -->
<!-- Required for ios < 14 or saving to album -->
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to save medias</string>
<!-- Required for ios < 14 or saving to album -->
Apparently I have to do this through XCode :|
Now it works 🙄 Apparently, a minor misplacement in this file will lead to misinterpretation by Apple's binary decoder. Who would have known :\
Currently, image upload doesn't quite work on the web, mostly because the embeds don't allow it to work (there is no way of locally adding a file on browsers because they don't keep the "real"
path
of the image as mobile apps do.https://github.com/dwyl/flutter-wysiwyg-editor-tutorial/blob/7c4fd5c30fdf15692d3e9175f51c5dede9912e73/lib/home_page.dart#L297-L301
So it's about time we make use of https://github.com/dwyl/imgup and upload our images so it's shown on all platforms!
imgup
and upload the image.Image.network
) from the uploaded URL