473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to pass image byte in servlets

i come up with this


This is my getters and setters in a java class.

Expand|Select|Wrap|Line Numbers
  1. private byte[] picture;
  2.  
  3. public Goal() {}
  4.  
  5. public Goal(byte[] picture) {
  6. this.picture = picture;
  7.  
  8. }
  9.  
  10. public byte[] getPicture() {
  11. return picture;
  12. }
  13. public void setPicture(byte[] picture) {
  14. this.picture = picture;
  15. }
  16.  


my problem is how do i pass image as byte to servlet request parameter eg
assuming i have
Expand|Select|Wrap|Line Numbers
  1. String picture = request.getParameter("picture");
  2.  
how do i code it as byte and pass it in servlet request. Is it like this
Expand|Select|Wrap|Line Numbers
  1. byte[] picture = null;
  2.  
  3.  
Jan 5 '13 #1
6 3911
Anas Mosaad
185 128KB
Use commons file upload and Multi-part form.

If you have a client application that can pass the file as string, you should encode it using base 64 encoding.
Jan 5 '13 #2
i tried this
String encoded = Base64.encodeFromFile("data/inputImage.png");

but it returns error method encodeFromFile not found[b]
Jan 7 '13 #3
Anas Mosaad
185 128KB
I don't know what Base64 implementation you are using. You may use the open source version from Apache Commons codec library. Here's how your code might look like using Commons-codec:
Expand|Select|Wrap|Line Numbers
  1. byte[] binaryData = null;
  2. // read data from the file into binaryData
  3. Base64.encodeBase64(binaryData );
  4.  
You can find the library @ http://commons.apache.org/codec/
Jan 7 '13 #4
what about the headers please
thanks
Jan 8 '13 #5
Anas Mosaad
185 128KB
Which headers do you mean?!
Jan 8 '13 #6
what about the headers please
thanks
Jan 8 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bent Kjeldsen | last post by:
Hi. I would like to upload an image (got File.Binary from ASPUpload) with a stored procedure. It works with a normal recordset with new/update and in ASP.NET, but in Classic ASP, I can't find...
4
by: Amir | last post by:
Hi, I'd like to know if it's possible to pass an image name (the IMG SRC attribute) from HREF element to a function that is activated by onClick event and creates a Web page. I have this HREF...
2
by: Herbert VON GRÜNENWALD | last post by:
i'v got: public static extern int ReadFile( IntPtr hFile, IntPtr lpBuffer, uint nNumberOfBytesToRead, ref uint lpNumberOfBytesRead, uint lpOverlapped);
0
by: Metallicraft | last post by:
I have a vb6 DLL that creates a bitmap in memory and saves the file. then it reopens the bitmap to read it into a byte array. is there a way to pass the vb6 byte array to the calling asp.net...
7
by: bookon | last post by:
I was running into the System.Drawing.Image.FromStream "parameter is not valid" on some of the images I was retrieving from a blob column in Sql Server. I thought there were corrupt images as...
7
by: james | last post by:
Hi, I am trying to insert a record into a database table, one field of which is a byte array. Using the below: Byte imgArr; .... <code to put image into imgArr>
2
by: Skiran | last post by:
I have stored image address in the database (Ms-Access). I wanted to pass run time this image path to crystal report to display the image in report. I am using VB6, Ms-Access and Crystal report 8....
2
by: indhu | last post by:
hi all, Any idea of how to pass image value to shape. i ve 10 image boxes with differnt color gif associated to each image box. when i click image that color has to reflect in shape. pls help me...
1
by: thomas_okken | last post by:
I'm working on a little C# DLL that will let me capture audio from within Internet Explorer. The idea is that the C# object, once it is recording, will periodically invoke a JavaScript callback,...
3
by: computer_guy | last post by:
Hi Everyone, I run into a problem. I am trying to write an aspx that can dynamically generate an image based on some input parameters. Things are very simple if the size of the parameters is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.