André Silva
André Silva

Reputation: 1171

Uploading and loading images through jquery ajax

So, let me explain it better, I'm pretty sure the title doesn't says much.

I'm in charge of doing some improvements on the company system. Now the system saves the current image, as a file, and insert into the database the path of the image.

Then, what's the problem if it works? Well, if the server gets a lot of images being inserted all the time, the server will need some improvements, so my first thought was, why don't I save the image data to the database and load it through ajax call? That's nice, it won't make the server overload from lots of gigabytes from the images, won't have problems with duplicates and such, but when I call the ajax method from jQuery, the data sent to the server side is via query string and if the data is higher than 6000 characters, like most are when I use base64 encoding, I can't call the method.

My other thought was, send the image to the server side and then generate the data to save to the database, and when the user wants to see the image, the server transform the data to an image and sends to the client side. But the problem is, there are lots of users for this system, and sending/receiving lots of images will make the server get memory problems due to the high amount of requisitions.

So to make long story short, what is the best way to send/receive images from client to server and the opposite without overloading the server capacity.

P.S.: Sorry for the long post, I wanted to make a clear question.

Thanks in advance.

Upvotes: 2

Views: 680

Answers (1)

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

The server will overload even more storing the images in the DB. Most web servers serve static files (like images) very efficiently.

You have to think more about the problem before trying to solve it:

  • Is your problem bandwidth overload? Try resizing the images client side before upload (you can use tools like PlUpload). If you can't, at least resize them server side to serve them smaller and save on download bandwidth

  • Is your problem harddrive space overload? Again, resize the images client o server side.

  • Is your problem CPU overload? Try to determine the root code that is the cause of the spikes. Be aware that lots of requests will cause high CPU, and you might need a more beefy server (or another webserver)

Upvotes: 1

Related Questions