I'm using Oracle-MAF for mobile app development (Android and IOS). Having a requirement to capture media (image, audio and video) in the application and want to store into Oracle DB usually CLOB column.
So for I converted the captured media into base64 string (using commons-codec-1.10.jar) and passing through Rest webservice (Accept JSON/XML) to store into DB.
For image and audio length of the base64 string is fine, but for video it is consuming around 6.4 million of characters even for 2 sec video (2MB Rear camera) and this cause slow down the application and resulting Java heap space error.
Is there any other way to convert the media content into String using Java which gives feasible solution?
If it's really necessary to save the videos in CLOB/BLOB column of a table in DB then first save the content in a file and then have an asynchronous scheduler to save it in the DB. The best would be to have this scheduler running in another Java VM not to interfere with the app server running your server side.
If you can save all binary content as binary in a file and a path in the DB. File systems are the best solution for serving binary data anyway.
Related
What is the correct/proper way to upload files to a server? I'm only talking about small files such as images, text files, and excel/word files.
I know that I can upload images to the database using BLOB. But what about the others?
I have a table called "Ticket" which contains information such as date created, ticket number, caller, attachment, and etc.
I'm having problems on how to upload an attachment to a server.
The first option should be uploading the image to a file server and stored the file id or uuid in your ticket table, or a OneToMany table stores all attachments.
Always void using BLOB to store image binary in database. Database has this capability doesn't mean it's a good way to use it.
If you are working on a small project, you may not see the problem. If the concurrent is relatively high,
Imagine you store the files in the database, even all are just images, whenever you retrieve the tickets, the a-few-MB image will be in the memory. It's a waste of server memory.
If you are using some ORM to retrieve the list, which will be worst and your server can be easily OutOfMemory.
One more thing is that if your system has Web Application Firewall in front, it's also advisable to separate file upload with normal form submission.
I have to store images from android app in Azure SQL database, I have tried to search on stack-overflow and googled it on many other sites , but I couldn't find an appropriate answer. I have seen some way on some sites but It was in C#, but I am a java guy. I tried it to find a way on Azure portal, where I just found a Easy Table function through which I can just make a table with no data type to save image.
Plase suggest me a way.
My task is that I have to save one image and 2-3 text strings through android app.
Thanks in advance.
Per my experience, normally saving images in Azure SQL Database is not a good idea. On Azure, the best practice is creating an Azure Mobile App instance to handle the request to save images using Azure Blob Storage. But by now, the Azure Mobile App only supports C# & NodeJS, and I think NodeJS is easy for you, which is express.js on Azure. Please see the tutorial below to know them.
How to use the Azure Mobile Apps Node.js SDK
How to use Blob storage from Node.js
Or you can directly use Azure Blob Storage in Android, that you can refer to the offical documents & samples.
Sample: Azure Storage Service - Photo Uploader Sample for Android
Library: Azure Microsoft Azure Storage SDK for Android
Tutorial: How to use Blob storage from Java
However, to save images in Azure SQL Database via easy table is a required needs. My suggestion is as below.
Encode image within Base64 to a string
Split the Base64 string to a string array, and make sure the length of the array string item is less than the length of the defined character column.
Save the index of the above array as a table column to easy table, then you can recover the Base64 string of image via concat the string array by the index.
Hope it helps.
I am currently developing my first Java based RESTful service that should be run on Heroku. This service manages some objects that have associated images. As Heroku is not able to store this images (apart from storing them in a database), I thought of using an external Content Delivery Network (CDN) like Amazon CloudFront. My first attempt to implement this would be as followed:
Encode the image (base64) on the client side.
Send the encoded image encapsulated in Json to the server side.
Decode the image on the server side.
Process the image (scale, create thumbnails, etc.).
Store the image in Amazon's CloudFront using the AWS SDK for Java.
Store a link to the image with the associated object in a postgreSQL database.
Now my question is, if this is the way to go, or if there is a better way to do this and if this GitHub project is a good point to start. If this helps to give an answer - the images are used within desktop and mobile as well as in web-applications.
Store the image in Amazon's CloudFront using the AWS SDK for Java.
Er, CloudFront doesn't store things, it caches things. If you want it stored, you need to put the image on S3 and pay for it every month.
Encode the image (base64) on the client side
Er, why? Just do a PUT or multipart-mime POST, and send the file as bytes.
Send the encoded image encapsulated in Json to the server side
Again, there's no reason to encode it, you can send the metadata + data in the same POST easily without encoding.
Store a like to the image with the associated object in a postgreSQL database
Storing images in a database is an anti-pattern. It makes the database harder to backup, slower to query, etc. Generally, you want to put the image in S3, and store the path in the database.
I am trying to upload a file, My front end application is in PHP and backend engine is in Java. They both communicate through PHP-Java_bridge.
My first action was, when a file is posted to PHP page, it will retrieve its content.
$filedata= file_get_contents($tmpUploadedLocation);
and then pass this information to Java EJB façade which accepts byte array saveFileContents(byte[] contents)
Here is how in PHP I converted the $filedata into byte array.
$bytearrayData = unpack("C*",$filedata);
and finally called the Java service (Java service object was retrieved using php-java-bridge)
$javaService->saveFileContents($bytearrayData);
This works fine if file size is less, but if the size increase 2.9 MB, I receive an error and hence file contents are not saved on to the disk.
Fatal error: Allowed memory size of 134217728 bytes exhausted //This is PHP side error due to unpack
I am not sure how to do this, Above method is not accurate, Please I have few limits.
The engine(Java) is responsible for saving and retrieving the
contents.
PHP-HTML is the front end application, It could be any thing for now its just PHP
PHP communicate with Java using PHP-Java-Bridge
EJB's methods are accessed by PHP for saving and retrieving information.
Everything was working fine with above combination, but now its about upload and saving documents. It is EJB (Application Engine access point) that will be used for any front-end application (PHP or another java application through remote interface (lookups)).
My question is how File contents from PHP can be sent to Java, where it does not break any thing (Memory)?
Instead of converting a file into an array I'd try to pass it as string. Encode the string into base64 in PHP and decode it into array in Java.
Another option is to pass the file thru the filesystem. Some Linux systems have /dev/shm or /run/shm mounted to a tmpfs, which is often a good way to pass temporary data between programs without incurring a hard-drive overhead. A typical tmpfs algorithm is 1) create a folder; 2) remove old files from it (e.g. files older than a minute); 3) save the new file; 4) pass the file path to Java; 5) remove the file. Step 2 is important in order not to waste RAM if steps 3-5 are not completed for some reason.
I have a small linux vps. I have written a Java client application, which needs to connect and submit large string data and images. The string data will be stored as regular text files on the server, and will be parsed by another Java application that will run on the server and use this uploaded files and images.
The next part of the problem is, because this Java client will be run by several users, I need some way to uniquely identify each uploaded file to the currently logged in user session on the website (the user needs to login on the website, to be able to run the tasks). Any suggestions or more efficient patterns ?
Don't write the stuff to files. Punch the uploaded data into 'raw' database tables by user ID. The batch job job can pull the data out, parse/format/fold/spindle/mutilate, and stuff the results into the real tables, then delete the raw data.