Unable to send CameraDialog image from NetworkRequest to server

470
3
Jump to solution
11-16-2022 02:27 PM
PhilPonce
New Contributor

I have created an asmx web service to accept images via NetworkRequest which works fine in development.  I'm sending the image using the following code snippet:

var body = {
"f": "json"
,"tags": fname
,"file": "@"+fname
};
send( body )

For development, the fname = "C:/Users/<username>/Pictures/IMG_1668636844943.jpg"  ("file:///" was removed to avoid the "Type error") works fine.

When I use my Pixel 7 to upload the image using the same code, it fails to call the web service at all.  However, when I comment out the "file" line in the body it calls the service and returns an error.

The image name from the Pixel 7 is "storage/emulated/0/Android/data/com.appstudio.player/files/Pictures/IMG_20221116_nnnnnnnnnnnnnnnnnnn.jpg"

When trying to load this image from the device, the web service is never even called.  Is there a way to trap the error within NetworkRequest as to why this fails?

0 Kudos
1 Solution

Accepted Solutions
TrevorFrame
Esri Contributor

Hi @PhilPonce,

Try checking out the Quick Report template to see how it is implementing adding attachments using NeetworkRequests. Start with the controls/pages/AddPhotosPage.qml which will use a custom component PictureChooser.qml. This will show how to find/use the correct file pathing where the image is stored. Under controls/FeatureServiceManager.qml, there are several NetworkRequest components being used to complete different types of request. Once has an id: uploadAttachmentNetworkRequestComponent.

Best,

Trevor

 

View solution in original post

0 Kudos
3 Replies
PhilPonce
New Contributor

I forgot to add the error messages from the AppStudio Console:

void NetworkRequest::sendFormData(const QUrl &, const QVariantMap &, const QVariantMap &) Skipping Parameter "storage/emulated/0/Android/data/com.esri.appstudio.player/files/Pictures/IMG_20221116_153524_8801901614242569162.jpg"

bool NetworkFormData::appendPath(const QString &, qint64, qint64) Cannot open: "storage/emulated/0/Android/data/com.esri.appstudio.player/files/Pictures/IMG_20221116_153524_8801901614242569162.jpg"

0 Kudos
TrevorFrame
Esri Contributor

Hi @PhilPonce,

Try checking out the Quick Report template to see how it is implementing adding attachments using NeetworkRequests. Start with the controls/pages/AddPhotosPage.qml which will use a custom component PictureChooser.qml. This will show how to find/use the correct file pathing where the image is stored. Under controls/FeatureServiceManager.qml, there are several NetworkRequest components being used to complete different types of request. Once has an id: uploadAttachmentNetworkRequestComponent.

Best,

Trevor

 

0 Kudos
PhilPonce
New Contributor

Thanks so much for the guidance, the Quick Report sample has a wealth of information in addition to the solution to my problem.  In that code I noticed that instead of using "file:///storage..." as the reference to the image when submitting to NetworkRequest, replacing it with "@/storage" resolved my error.  It was a little brutal getting to this point, but learned a ton on the journey... 

Thanks again, Phil

0 Kudos