Closed iDanielD closed 3 years ago
@iDanielD mobile_image_mounter
is used to upload developer disk images (i.e. file archives), not pictures.
You can probably use AFC (the Apple File Conduit) to transfer files to/from your phone. Haven't done it myself, though.
@qmfrederik Thank you for your quick response. I just tried using the AFC, but I cant see there an option to upload an image. I have updated my Code to something like this:
private void UploadImage(Image image)
{
var afcApi = LibiMobileDevice.Instance.Afc;
var byteArray = ImageToByteArray(image); // Returns a byte array from the selected image from my Computer.
afcApi.afc_client_start_service(DeviceHandle, out var afcClientHandle, null).ThrowOnError();
afcApi.??
}
I linked all possbile afc methods below.
@iDanielD AFC allows you to open a file (afc_file_open) and then write to that file (afc_file_write). That's how you would upload a file. It's very similar to the file APIs in C (fopen, fwrite, fread,...)
You'd need to figure out in which directory you need to save the images.
@qmfrederik Alright I will test it myself and write back if I got any results. Thank you.
@qmfrederik I cannot get it to run. I don't understand how I should upload such a picture, if I open an already existing file from my cell phone and then write new information into it? Will the picture not be overwritten then?
This is what I have tried (Not working)
private void UploadImage(Image image)
{
var afcApi = LibiMobileDevice.Instance.Afc;
ulong handle = 0;
uint bytesWritten = 0;
var byteArray = ImageToByteArray(image); // Returns a byte array from the selected image from my Computer.
afcApi.afc_client_start_service(DeviceHandle, out var afcClientHandle, null).ThrowOnError();
afcApi.afc_read_directory(afcClientHandle, @"/DCIM/101APPLE", out var dir).ThrowOnError();
afcApi.afc_file_open(afcClientHandle, @"/DCIM/101APPLE/IMG_1362", AfcFileMode.FopenRdappend, ref handle).ThrowOnError();
afcApi.afc_file_write(afcClientHandle, handle, byteArray, (uint)byteArray.Length, ref bytesWritten).ThrowOnError();
}
If you specify a path to a file which does not exit, afc_file_open
should create a new file on the device.
Well, I see the problem. The file is being written, but I can't see it on my phone. I thought that if I write "@"/DCIM/101APPLE "" in the path, it will be displayed in this folder so I can view it in windows. But this is not the case. Is there maybe a common path for the albums on my iPhone where I can store my file and see it?
You should be able to use afc_read_directory
to get a listing of the directory contents, and get an idea of the directory structure (and know to which folder you can upload your picture).
Also make sure to properly close the file handle with afc_file_close, etc... .
@qmfrederik Ok after several attempts to find the right path, I decided to create a new album and save the pictures in it. Do you perhaps know a way to create a new album on the device where I could save my pictures?
Has anyone found a solution?
So the solution would be to edit the "PhotoData/Photos.sqlite" database. This way the added or deleted Images would als be added or removed from the gallery.
Hey,
I am having trouble uploading pictures from my computer to my iOS mobile device. So far I have tried to use the method "IMobileImageMounterApi.mobile_image_mounter_upload_image", but I have no idea what to use as a parameter. Below I have my code. Could someone help me with this?
Thank you in advance!