How to upload to Object Storage from client side, then save a public URL for that file

Hello, I apologize for my bad English, I will try to explain as good as I can.

I have a PHP website(my first actually) where users can upload photos.

Currently, I am uploading them to my Linode server then from the server to the Linode bucket using AWS SDK for PHP.

However, as users increase the CPU usage is getting very high when multiple users upload photos concurrently. On the 4 core, 8 GB Linode the CPU goes as high as ~85% us using the "top" command, and the site slows down noticeably. Neither Apache nor PHP-FPM errors and there is still around 3GB memory available.

I want to upload the photos directly from the client side using JavaScript to take the load off my web server.

I need to have a publicly available URL to the photos which will be saved in MySQL. The URL will be used as image "src" attribute.

How can I achieve this?
Here's my understanding of what needs to be done:

  1. Client request to server to upload file.

  2. Server generates pre-signed URL and returns to client.

  3. Client Upload file(image) directly to Linode Storage using the pre signed URL.

  4. //This is where I am really confused//

If client uploads using pre-signed URL then how can I get a public URL for that image which does not expire. Is there some work around for this, or is my understanding wrong?

Although this might be a silly question as I am a beginner, I would really appreciate any input on this.

Thanks.

4 Replies

Hi there -

This is a great question for the Community and I'm going to add some additional tags to it to give it more visibility. Also, I'm going to link you to a few documents that might get you pointed in the right direction.

If client uploads using pre-signed URL then how can I get a public URL for that image which does not expire. Is there some work around for this, or is my understanding wrong?

You can always host your objects with a static site -

Host a Static Site with s3cmd

Objects in your buckets can be publicly accessible - it's explained in this section of our guides:

Object URLs

Also, here's a general how-to guide on using our Object Storage:
How to Use Object Storage

You may be better off looking at the AWS SDK for JavaScript, and handle the authorisation and upload completely with JavaScript.

You can then get the public URL from the JS SDK to pass to your PHP.

@webrefiner did you solve this?

If yes, can you share how?

Also looking to do the same, is there any documentation on using the aws-sdk with linode's s3 implementation?

I was able to use a rust-s3 crate and adjust the endpoint to us-east-1.linodeobjects.com but I can't seem to find anything for adjusting the endpoint using the aws-sdk; however, I really don't want to spin up an api just for this, and would rather implement it into a nextjs webapp that's already up and create an api endpoint using javascript.

Albeit, I only started looking for some kind of documentation this morning.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct