PhoneGap File Upload (other then images) using file transfer - jquery-mobile

i have a a sequence of task to do with the phoneGap.
one is that i have to select the file from library/storage of the device and then upload to server.
With the reference from the documentation form the phoneGap site here i found somethings related to the image upload and i successfully able to run that as well, but
the problem is that when i browse the device it only shows the image files, how can i select the other files?? here is the code
function getImage()
{
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto, function(message)
{
alert('get picture failed');
},{
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
});
}
selection and uploading succesfull only in case if selection is made from photo library , the app crashes when selection using file manager ,, how to handle this ??
any help will be appreciated
thanks

You can use the file chooser plugin to pick a file (android only), and then upload it

Related

The file "test.pdf" could not be opened on mac. [Ionic-iOS]

I am trying to save the pdf in iOS using the Ionic Filesystem. I am using the below functions for writing the files.
Filesystem.writeFile({
path: 'test',
data: EStatementConstant.BinData,
directory: Directory.Documents,
encoding: Encoding.UTF8,
});
Where EStatementConstant.BinData is my base64 data [validated] which I am getting directly from the API service.
The problem is that I am unable to open the file on a Mac. I didn't find any function to decode.
I am using capacitor v-3.
https://capacitorjs.com/docs/apis/filesystem?_gl=11i199tw_gaMTYzMjY4MzAzMi4xNjM0ODQxNDI4_ga_REH9TJF6KF*MTY0ODgwMzI4NS40OS4wLjE2NDg4MDMyODUuMA..#type-401
Note:- I am unable to save the pdf data without encoding in iOS. Also, I can not use the Cordova plugin. I am struggling with this for the last few days. Please help.

open camera in webview (ios 14, ionic)

I am developing an application with ionic, I want to open the camera to run a tensorlfowjs model.
Ionic packages html and javascript files in a native application and executes them in a webview, with the web version and the android version I have no problems.
But in the version for ios it is giving me a lot of problems opening the camera from the webview.
let video: HTMLVideoElement = document.getElementById("vid") as HTMLVideoElement;
var mediaDevices = navigator.mediaDevices;
mediaDevices
.getUserMedia({
video: true,
audio: true,
})
.then((stream) => {
// Changing the source of video to current stream.
video.srcObject = stream;
video.addEventListener("loadedmetadata", () => {
video.play();
});
})
.catch(error=>console.error('error open camera', error));
I have added the permissions for the camera in info.plist, when I run that code it shows a alert requesting permission for the camera the first time, but I always get an empty error message in the js code
[error] - error open camera {}
I am testing with a device with IOS: 14.4.2 this https://pastebin.com/Dx44XMYY is the system log. where you can see the following message
pp UserMediaPermissionRequestManagerProxy::denyRequest(F6CC2F45DD55FA12) 15, reason: InvalidConstraint
I do not know how to move forward, what to try, or what the reason for the error may be.
I appreciate any advice
Edit: As #jcesarmobile says, it seems to be ios 14 problem, I have tested the code with ios 15 and it works. I appreciate any advice on how to fix it
Since you are setting audio to true, you also need the microphone usage description
NSMicrophoneUsageDescription

How to save file with Capacitor on iOS?

I have the following code (adapted from this tutorial) that I use for saving files from backend:
import { FilesystemDirectory, Plugins } from '#capacitor/core';
const { Filesystem } = Plugins;
await Filesystem.writeFile({
path: "filename.txt",
data: "base64 data",
directory: FilesystemDirectory.Documents,
});
This codes works fine on Android, even creates the Documents directory in the root of internal storage. Unfortunately, on iOS no file is created, no mater what directory I use (I've tested it with Documents, Data and ExternalStorage).
When I put this code block inside try..catch, nothing is thrown, so the operation is supposedly completed successfully, just no file is saved. Tested on one Android device and two iOS.
iOS doesn't allow accessing file storage directly. I made it work with Ionic-native's FileOpener like this:
import { FileOpener } from '#ionic-native/file-opener/ngx';
import { FilesystemDirectory, Plugins } from '#capacitor/core';
const { Filesystem } = Plugins;
const result = await Filesystem.writeFile({
path: "filename.txt",
data: "base64 data",
directory: FilesystemDirectory.Documents,
});
this.fileOpener.showOpenWithDialog(result.uri, 'application/json')
It opens a dialog where you can select where to save your file. It's a bit confusing as the function's description is "Opens with system modal to open file with an already installed app" but saving works with it as well.
You need to also install cordova-plugin-file-opener2 and put ionic FileOpener to providers in app.module.ts. If you are not using Cordova otherwise, you don't need to do Cordova setups, it works alongside Capacitor as a separate plugin. As far as I'm aware, Capacitor doesn't provide a solution for downloading in iOS.
I've encountered the same problem (while having capacitor 4.2.0 only) and solved it by adding the following permissions in my Info.plist:
<key>UIFileSharingEnabled</key>
<string>YES</string>
<key>LSSupportsOpeningDocumentsInPlace</key>
<string>YES</string>
After this, using directory Directory.Documents has made me visible a Documents directory with the name of the app under the Files App.
Hope it helps.

Flutter image_picker video gallery OSError: Operation not permitted [Errno 1] IOS 13

I am using flutter image_picker and almost all is good except for when i try to do something with file generated on pickVideo from gallery (just on IOS 13 real device) it give error:
OSError: Operation not permitted [Errno 1].
Some extrange is that this video file can play with video_player and i can work good with camera file and image pick file generated with image_picker, but video gallery file can not do another thing than play with video_player.
For example, trying to get file size or copy it to another file fails, code example:
var videoFile = await ImagePicker.pickVideo(source: ImageSource.gallery);
print("File path........${videoFile.path}");
print("...................Size: ${await videoFile.length()}");
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
File newfile = videoFile.copy("${appDocPath}/video.MOV");
I saw that all permissions are good, mainly NSPhotoLibraryUsageDescription on Info.plist, but it does not work.
I need to say that on android all is working fine.
I hope some one can help me.
please go through the documentation of Image_picker where it says for ios setup:
Add the following keys to your Info.plist file, located in /ios/Runner/Info.plist:
NSPhotoLibraryUsageDescription
NSCameraUsageDescription
NSMicrophoneUsageDescription
https://pub.dev/packages/image_picker
I solve my problem using another library call file_picker, i think image_piker is not workin good since IOS 13, they need upgrade it.

File Folder error when using camera

I have followed this docs in implementing in taking a photo and picking a photo in Xamarin. I was able to implement and worked in picking a photo but I have error in using the function TakePhotoAsync() which is used to open the camera to take picture. I have googling for possible solutions but nothing works for me. I did not modify any permission or add from the current which work on Picking a photo.
It crashes in this line:
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium
});
I am testing in the emulator: AVD_for_Galaxy_Nexus(Android 6.0 - API 23)
Exception:
System.ArgumentException: Unable to get file location. This most likely means that the file provider information is not set in your Android Manifest file. Please check documentation on how to set this up in your project.
By the way, I did solve the error by downgrading the version of the plugin to Xam.Plugin.Media 3.1.2 from Xam.Plugin.Media 3.1.3. I didn't change anything in my codes.

Resources