How to resize an image before uploading it via Swift's webView?

We have a website built with JQueryMobile, which is displayed to our users through a phone application.

One of the pages is composed of a fileChooser, with which the user chooses the image from the device and then a button that has the task of uploading the photo to our server.

The image must be resized before loading.


Android side in the onActivityResult method, we capture the moment and resize the image correctly.


Android

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode==FILECHOOSER_RESULTCODE)
  {
  //Resize image
  }
}


In Swift how do I capture that moment to resize the image and then load it?

Summing up:

  • I enter the page (it works)
  • I click on the button to choose img (HTML tag input type = "file") (it works)
  • I select image (it works)
  • Resize image (to be developed)
  • Image upload (works)


Searching the internet I found the code to resize the image.

In Swift what is the method corresponding to Android's onActivityResult?


I hope I have been clear enough

Replies

What would be the problem to resize the image when you return from selecting it ?

Yes, capture the moment in which I have the image and resize it

Can you show the code where you select the image ?

The code is in a php page implemented with JQuery and the Swift side is called in the webView.

I can't post the code.
I would like to post photos or links but the forum won't let me

I don't understand exactly where the image is and where it is accessible.


Where is the image you choose ? I understand on server.


Then you display the image, so you get it on device ?


When you ask to upload, is the image

1- transfered from device to your server or

2- is it from server to server ?


In case 1, you should implement the resize in the upload button action

In case 2, you have to access to server code I fear.

>would like to post photos or links


See For Best Results - Read the Label

I'm on a device, for example IPhone XR.


I open the application which consists of a webView that calls a website written in php and uses JQuery Mobile


On a page we have the html input type = "file" tag which allows the user to select an image from his device.

Another button sends it to our server.

And the whole process happens correctly.


In android we capture this moment and before sending it we resize the chosen image.


This happens in

@Override  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  super.onActivityResult(requestCode, resultCode, data);  
  if (requestCode==FILECHOOSER_RESULTCODE)  
  {  
  //Resize image  
  }  
}

We need to do the same thing in Swift

  • I know this is from a little while ago. Did you get the answer? I'm in the same boat here. Android seems simple but can't find where to intercept the File Chooser and Camera before action.

  • Any Updates here, I'm facing the same issue :-/

Add a Comment