Posting an image to a php-server

Hi

I’d like to select a picture and send it to my php-server.

I can select fine - but posting it seems to be a problem. There is no web_api.postfile in Thunkable X.

Can anyone help me on this task?

Hi,

How and where do you select the file?

Hi actech - thanks for answering

I just choose through the photo_library component.

If somewhere else is easier, then I’m game…

Now I understand. If you have experience with JavaScript, then I would suggest the option of working through WebViewer. To do this, open the html file in WebViewer with the form of sending the file to the server with the element

The second option is after selecting a file using to encode it in base64 format, and then you can send files anywhere (in messages or a database) in this text format. As an example, look at the scrFileViewer screen from the project (but this does not work on Android).

https://x.thunkable.com/projects/5c8e64dfe1aad2f778a4c5ad/project/properties/designer/

1 Like

Thank you for suggesting.

I like the Jscript you made for converting to base64 - but if it doesn’t work on Android, then I cannot use it.

The first suggestion is to open a page, and then select the image through the web-page form? Just like on https://imgur.com/upload ?
When I go there on my normal browser (on my phone), it works just fine - but when I try through the webwiever, then nothing pops up when I click “browse”.

Thank you for the replys.

Yes, the file upload form can be implemented in several ways:

  1. Create an html file with a form, add this file to the project and point it to the link in WebViewer
  2. Open a form in WebViewer online to upload the file to the server.
  3. Use the Thunkable X example from https://docs.thunkable.com/media-db and first save the image to the Cloudinary repository, and then send the resulting link to the saved file to the repository, for example, in your php script, which this link will save the file on your server

I would really like to avoid cloudinary, as a detour before my own server. So option 3 is out.

When I try option 1 - I’ve tried with PHP Tutorial - File Upload and Imgur: The magic of the Internet - nothing happens, when I click the “find file” button within webview. It just doesn’t seem to respond - or somehow doesn’t allow the file to be searched for.

Option 2 also seems fine, but I don’t know how - I’ve tried adding this:
<form action=“upload.php” method=“post” enctype=“multipart/form-data”>
Select image to upload:
<input type=“file” name=“fileToUpload” id=“fileToUpload”>
<input type=“submit” value=“Upload Image” name=“submit”>
</form>
To the body tag of the webviewer, but that didn’t do it…

I want to clarify one point. When you press the file selection button on Android, it is pressed, but nothing happens or a screen with applications opens with which you can select a file?

Right now - nothing happens

I would like it, if a screen opened, where you could select a file.

I understood. <iput type = “file” just doesn’t work on Android in WebViewer. Try to open the file with the download form through an external browser using the “open link” block.

Does the external browser work?

I can’t check it out, because with Thunkable Live there’s a problem again.

But doing that - I end up in chrome, and I am no longer in my own app - with no way to get back.

55

That is not what I want.

You probably noticed that when working with Thunkable X you have to invent a lot of crutches? In fact, everything is simple - either invent crutches in Thunkable X, or use a more functional tool for developing applications for Android.

Well - I’d like to invent a crutch for this - and you’ve provided important information, in that input type=file doesn’t work.

I’d like to look into the option for adding a form to webview directly - I don’t think I understand that path yet. Maybe type=file still doesn’t work there?..

I’m still open to other options for sending photos from the mobile to my php-server… It has to be possible!

Well, if I find another option, I’ll write.