Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving the uploaded file to a permanent location, not working on mobile devices. #199

Closed
Pieter3033 opened this issue Jan 22, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@Pieter3033
Copy link
Contributor

Hi all,

sqlpage.uploaded_file_path Returning NULL when submitting on a mobile device.

On computer:
Works perfectly fine, file path is inserted into database.

Code:

INSERT INTO Images (JC_num, file_path, title)
VALUES(
        $
       ,sqlpage.uploaded_file_path('img')
       ,'test'
)

Results: (Reference from DB)
image

On Mobile device:

Using the exact same code to save the image locally.
The file path just returns as NULL.

Reference from DB:
image

To Reproduce

  1. Create a webpage with a form to submit images.
  2. Host the website so that it can be accessed from a mobile device.
  3. Using the mobile device upload the file_path to the database.

The file_path will return as NULL.

@Pieter3033 Pieter3033 added the bug Something isn't working label Jan 22, 2024
@lovasoa
Copy link
Collaborator

lovasoa commented Jan 22, 2024

Hi! It looks like the mobile device did not send the file. Did you try from a different browser or device ?

On a separate note: it looks like you are saving temporary file paths in a permanent store (the database). Are you sure this is really what you want to do? You probably want to save files in a persistent location, where they won't be automatically deleted, and save that permanent path in the database.

@Pieter3033
Copy link
Contributor Author

Hi @lovasoa, Hope you are well.

On a separate note: it looks like you are saving temporary file paths in a permanent store (the database). Are you sure this is really what you want to do? You probably want to save files in a persistent location, where they won't be automatically deleted, and save that permanent path in the database.

Thanks for the advice.
Correct, I had to remove the code that saves it to a persistent location before loading the path in the database, because I received errors when I tested the image upload on my phone.

So I have tested on 3 mobile devices, and 3 different browsers.

Safari (iPhone)
• Worked

Chrome (Android)
• Worked on the second Android device, but not the first Android device.

Firefox (Android)
• Worked on both Android devices

On the first Android device I have cleared cache and cookies, made sure that Chrome has all the permissions, I just cant see why it would not upload the images.

I confirmed that both android devices chrome version is the same.

Can you maybe think of a reason why the images did not upload?

@Pieter3033
Copy link
Contributor Author

On a separate note: it looks like you are saving temporary file paths in a permanent store (the database). Are you sure this is really what you want to do? You probably want to save files in a persistent location, where they won't be automatically deleted, and save that permanent path in the database.

I have moved my file first and then inserted the path into the database. It has moved the file to a persistent location, but it inserted the temp file location in the DB, am I missing something?

Code:

SET image1_path = sqlpage.uploaded_file_path('reg_img')
SET exec_image = sqlpage.exec( 'cmd','/C','move', $image1_path, 'C:\SQLPage\Jobcard_Images');

INSERT INTO Images (JC_num, file_path, title)
VALUES(
        $
       ,sqlpage.uploaded_file_path('reg_img')
       ,'reg_no'
)

Result:
image

@lovasoa
Copy link
Collaborator

lovasoa commented Jan 23, 2024

You are saving the uploaded_file_path instead of the new path you created.

What you can do is

SET image1_path = sqlpage.uploaded_file_path('reg_img');
SET target_file_path = 'C:\SQLPage\Jobcard_Images/' || sqlpage.random_string(16) || '.jpg';
SET exec_image = sqlpage.exec('cmd','/C','move', $image1_path, $target_file_path);

INSERT INTO Images (JC_num, file_path, title)
VALUES($, $target_file_path, 'reg_no');

@Pieter3033
Copy link
Contributor Author

Perfect, that answers alot of questions. Thank you for your time.

@Pieter3033
Copy link
Contributor Author

Hi @lovasoa, I was just wondering why the images did not upload using chrome on my mobile device.
Do you maybe have an educated guess or answer.

@lovasoa
Copy link
Collaborator

lovasoa commented Feb 28, 2024

I haven't been able to reproduce your issue. Maybe you can share an small sample application that reliably reproduces the issue ?

Or a network capture from the mobile device showing the issue ?

@lovasoa
Copy link
Collaborator

lovasoa commented Feb 28, 2024

@Pieter3033 : actually, thinking about this, I guess you are not testing with the exact same file from the different devices, are you ? Isn't it possible that you simply tried with files larger than your configured max_uploaded_file_size (5 MiB by default) on mobile, and with smaller files on desktop ?

Did you have a look at SQLPage's logs ? Do they contain a line saying Could not read request data: Failed to save uploaded file: payload reached size limit at the time when you upload a file that fails to upload ?

@lovasoa
Copy link
Collaborator

lovasoa commented Mar 23, 2024

v0.20.1 adds a function that should make your life easier: https://sql.ophir.dev/functions.sql?function=persist_uploaded_file#function

and it doesn't silently ignore large files

@Pieter3033
Copy link
Contributor Author

Hi @lovasoa, trust you are well.

With the new update I know exactly what the problem is, it was not an error with the browser nor the device being used.

I did not know at the time but the max_uploaded_file_size is the max size per webpage, and not per image.

You are correct, I did not test with the same files every time.

The solution I found is to download an app that automatically lessens the image size.
With this solution I am able to upload multiple images on a single page.

SQLPage persist_uploaded_file definitely makes things easier.

@lovasoa
Copy link
Collaborator

lovasoa commented Apr 2, 2024

Great, and thank you again for bringing this to my attention. In the end, we made SQLPage better and easier to use for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants