Save byte array (image) to file with servlet
Good day.
I should must to save a png image to file.
I have a byte array of the image.
This work is in a servlet.
How can I do it?
Best regards.
Stefano Errani
Good day.
I have a byte[] and then I have used
FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("/public_html/mcfoto/foto1.png"));
fos.write(bt, 0, bt.length); // byte[] bt
fos.close();
This on my web server that has public_html as root web directory.
The server is in multi domain.
In this mode I have an error.
Then I have tryied to use
FileOutputStream fos = new FileOutputStream("http://www.stefanoerrani.it/mcfoto/foto1.png");
and
FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("http://www.stefanoerrani.it/mcfoto/foto1.png"));
In both ways I have obtained an error.
At last I have tryied in my localhost (local machine) using
FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("/mcfoto/foto1.png"));
All run correclty.
The Application Server is Tomcat with Apache HTTP Server.
The first server (of www.stefanoerrani.it) has Linux as OS.
My local server has Windows as OS.
I should want, if it's possible, an help.
Best regards.
Stefano Errani
Similar Messages
-
Couln't save a buffered image as BMP with java 1.4
Dear friends,
I tried to save a buffered image as BMP with java 1.4. When I run the program ,it executes sucessfully, but no image wasn't created. When I tried the same code with java 1.5 got the right result.
This is the code I have written.
public static void saveBMPFile(BufferedImage bufferredImage, String fileName) throws Exception{
// TODO Auto-generated method stub
try {
Iterator iter =
ImageIO.getImageWritersByMIMEType("image/bmp");
// Get first writer
if (iter.hasNext()) {
ImageWriter writer = (ImageWriter) iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionType("BI_RGB");
FileImageOutputStream fios = new FileImageOutputStream(new File(fileName));
writer.setOutput(fios);
IIOImage image = new IIOImage(bufferredImage, null, null);
writer.write(null, image, iwp);
bufferredImage.flush();
fios.flush();
fios.close();
} catch (Exception e) {
throw e;
please help me to find its solution.
thanks & regards
K P JyothishPlease use code tags http://forum.java.sun.com/help.jspa?sec=formatting
I can see no else for "if (iter.hasNext()) {", so if no encode is found, no error message would be displayed. -
I' can't open images or files with trial version of Photoshop cc
I' can't open images or files with trial version of Photoshop cc. Photoshop starts, it seems ok, but don't work.
Illustrator cc works very well. Why?1. I open Photoshop cc Trial version
2. I click "continues with the trial version" (in italian version)
3. File>Open> psd (cs5) or jpeg files
I can't even open a new document. (File>New> etc..)
All files can be opened by Paint, Ilustrator etcc. Only Photoshop doesn't work.
I just see this -
How to save Byte Array of raw data into JPEG image.
Hello!
I have a image and I stored its data as byte array as
bimage = bitmap1.getRawData();
now I have Byte[] bimage, I want to save it as .jpeg image.
and show that image..............the short way is this:
ImageIO.write(bimage, "jpeg", new File("image.jpg"));
Where you use the original Image object... but it has to be a java.awt.image.RenderedImage (which a java.awt.image.BufferedImage is). So this method would come in handy.
public static BufferedImage getBufferedImage(Image img) {
// if the image is already a BufferedImage, cast and return it
if((img instanceof BufferedImage) && background == null) {
return (BufferedImage)img;
// otherwise, create a new BufferedImage and draw the original
// image on it
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(img, 0, 0, w, h, null);
g2d.dispose();
return bi;
}If the byte array you have is raw image data, then you can look at the javax.imageio package and see what you can do with those classes. -
Save byte[] array to file
Hi,
I've read a .jpg picture off the hard disk and stored in a byte[] array. I've altered some of the bytes and want to save the file back to .jpg. Is there a method available in java which allows me to do this?
Thanks and regards,
Krt_MaltaFileOutputStream#write(byte[] array).
-
Display byte array image or ole object in Section through dynamic code?
To Start I am a Complete Newbe to Crystal Reports. I have taken over a project originally written in VS2003 asp.net using SQL Server 2005 and older version of Crytal Reports. I have moved project to VS2010 and Cryatal Reports 10 still using SQL Server 2005. Have multiple reports (14 to be exact) that display data currently being pulled from database suing a dataset, each report has from 4 to 14 Sections. I have modified database table with two new fields. Field1 contains string data with full path to a scanned document (pdf or jpeg). Field2 holds a byte array of the actual image of the scanned document. I have tested the database and it does infact contain the byte array and can display the image via VB.net code. I can make the report display the scanned image using ole object.
Now my real question: I need to add a new Section and it should display either the byte array of the scanned image or the actual scanned image (pdf or jpeg) . How can I have it do either of these options via code dynamicly while application is running?First; only CRVS2010 is supported on VS2010. You can download CRVS2010 from here;
SAP Crystal Reports, developer version for Microsoft Visual Studio: Updates & Runtime Downloads
Developer Help files are here:
Report Application Server .NET API Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/xi4_rassdk_net_api_en.zip
Report Application Server .NET SDK Developer Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/xi4_rassdk_net_dg_en.zip
SAP Crystal Reports .NET API Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet_api_2010_en.zip
SAP Crystal Reports .NET SDK Developer Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet_dg_2010_en.zip
To add the images, you have a number of options re. how to. You even have two SDKs that y ou can use (RAS and CR).
Perhaps the best place to start is with KB [1296803 - How to add an image to a report using the Crystal Reports .NET InProc RAS SDK|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233393336333833303333%7D.do]. The KB describes how to add images to a report using the InProc RAS SDK, but also references other KBs that use CR SDK.
Also, don't forget to use the search box in the top right corner of this web page.
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports] -
Displaying Byte Array images in coldfusion
This has been driving me crazy for a couple of days now.I
have a Java class that returns pictures stored in a DB as a Byte
Array.
I am able to display the image but that is all i am able to
do - I want to display the image name, description etc in a HTML
before i display the actual image but i can't seem to find a way to
do that.
I tried using CFcontent as well and that did not help
either.This is what i am currently doing - and all that displays on
the screen is the picture and all content before the picture is
nowhere to be seen.
Picture Name: #variables.picName#
Picture Description:#variables.picDescription#
<cfscript>
context = getPageContext();
response = context.getResponse().getResponse();
out = response.getOutputStream();
response.setContentType("image/jpeg");
response.setContentLength(arrayLen(session.picture));
out.write(session.picture);
out.flush();
out.close();
</cfscript>
Any help will be greatly appreciated.Mark,
Note that the portal sets the content type (e.g, text/html) and encoding
as the portal page starts rendering. In your case, the
setContentType() would be useless since the servlet container won't let
you change it. You can either use a popup browser window for the pdf as
Kunal suggested, or use an iframe if you want to render the pdf inside
the portlet window.
Subbu
Mark Gilleece wrote:
Hi,
i need to display a PDF file. The PDF is stored in a byte array. This works fine when i run my code (see below) from the .jpf via the debugger/browser, but when i use it as a portlet, in the portal, it does not work ?
Any help is much appreciated.
Thanks
Mark
byte[] pdfDocument = docStore.getPDF();
ServletOutputStream outPdf = response.getOutputStream();
response.setContentType("application/pdf");
outPdf.write(pdfDocument);
outPdf.flush();
outPdf.close(); -
Okay... I'm new to using servlets. Not so much to jsp, just to using servlets. I have one process on our site that is using servlets and I'm trying to mimic how that is using em but am having no luck.
I am trying to open files with a servlet. I have the class built and compiled, but mainly pulled it from Java World. I evenually will need to pass the servlet the filename and path I want open but in this example it has the file set. My problem is I want to send users to a jsp file where I check user authentication and call the servlet to open the doc, but I don't know how to call the servelet or what to send it. If someone could maybe walk me through this.
Here's my servlet:
package cmxx.fileServe;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class fileServe extends HttpServlet {
final static String CONTENT_TYPE_DOC = "application/msword";
final static String CONTENT_TYPE_HTML = "text/html";
final static String document = "/docs/form_41.doc";
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
doGet(request, response);
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
PrintWriter out;
out = response.getWriter();
HttpSession websession = request.getSession(true);
response.reset();
response.setDateHeader ("Expires", 0);
response.setDateHeader("max-age", 0);
try {
response.setContentType(CONTENT_TYPE_DOC);
FileInputStream fileInputStream = new FileInputStream(document);
ServletOutputStream servletOutputStream = response.getOutputStream();
int bytesRead = 0;
byte byteArray[] = new byte[4096];
while((bytesRead = fileInputStream.read(byteArray)) != -1) {
servletOutputStream.write(byteArray, 0, bytesRead);
servletOutputStream.flush();
servletOutputStream.close();
fileInputStream.close();
} catch(Exception ex) {
throw new ServletException(ex.getMessage());
} /* end doget */
} /* end class */I'm trying a new servlet. But am getting a few compile errors. Can someone help?
Here are my Errors:
43 cannot resolve symbol
symbol : class URL
location: class cmis.fileServe.fileServe2
URL url = new URL(fileURL);
^
43 cannot resolve symbol
symbol : class URL
location: class cmis.fileServe.fileServe2
URL url = new URL(fileURL);
^
57 cannot resolve symbol
symbol : class MalformedURLException
location: class cmis.fileServe.fileServe2
} catch(final MalformedURLException e) {
^
Code:
package cmis.fileServe;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class fileServe2 extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
ServletOutputStream out = res.getOutputStream();
// Set the output data's mime type
res.setContentType( "application/pdf" ); // MIME type for pdf doc
// create an input stream from fileURL
String fileURL = "http://www.adobe.com/aboutadobe/careeropp/pdfs/adobeapp.pdf";
// Content-disposition header - don't open in browser and
// set the "Save As..." filename.
// *There is reportedly a bug in IE4.0 which ignores this...
res.setHeader("Content-disposition", "attachment; filename=Example.pdf" );
// PROXY_HOST and PROXY_PORT should be your proxy host and port
// that will let you go through the firewall without authentication.
// Otherwise set the system properties and use URLConnection.getInputStream().
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL(fileURL);
// Use Buffered Stream for reading/writing.
bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
// Simple read/write loop.
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
} catch(final MalformedURLException e) {
System.out.println ( "MalformedURLException." );
throw e;
} catch(final IOException e) {
System.out.println ( "IOException." );
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
} /* end class */ -
How to send byte array and String values to servlet from Swing application
Hi all,
I am new to swing, servlet, and socket connection.
I have swing application to draw images and some input data. I dont know to send to server.
byte[] buf = baos.toByteArray();
URL servletURL = new URL("http://10.70.70.1:8080/servlet/SaveImage)
URLConnection conn = servletURL.openConnection();
conn.setDoOutput(true);
BufferedWriter out = new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
out.write(buf&a=aaaa&b=bbbbb);
out.flush();
out.close();
can I do like this. Strings are received in server side perfect. but i cant get byte array data. Please help me.
Thanks in advance.<img src="myservlet">
In your myservlet:
response.setContentType("image/jpeg");
then write your image date via ImageIO that uses response output stream. -
How do I save stock footage as flash file with transparent background?
Hi
I have some stock footage of smoke on a black background (.mov format) that I would like to convert to a flash file with a transparent background, which I will be overlaying over a PNG image on a webpage.
I have managed to remove the black background in After Effects using a plugin called UnMult, but when I try to render as a FLV file in AE, even though I check the option to preserve the alpha channel and encode using the On2 VP6 codec, I still get a black background.
So I am wondering what else to try, whether it be with AE or Flash CS4. Is there a way of achieving this effect by directly importing the MOV file into Flash CS4 and removing the black background there, or do I have to use AE, and if so, how to achieve the effect I am looking for?
I would be grateful for any help in getting this together
Thanks
NickYou can put the video file in a movie clip and change it's
blending in the properties panel to multiply or screen.
Emil Georgiev - Flash and Web Design -
Can I speak into my mac and save it as an audio file with garage band
Can I speak into my mac and save it as digital audio file?
Looking at the specs, the mini does not appear to have a built-in microphone as the iMacs do. You can't just plug a microphone into the input socket, as that is line level and a microphone doesn't have enough output. Your easiest move would be to buy a USB headset such as the one Plantronics makes for use with Skype: this should work straight off.
Sound Recorder is a simple audio recorder: I've not used it, so I don't know if it's any good, but it would at least cost you nothing to try it.
Amadeus II and Amadeus Pro are reasonably priced and are fully featured sound recorders and editors which can save in a number of formats. -
How can I save multiple emails as separate files with 1 export?
I need to save hundreds of emails as separate files. If I select all of the emails, then export as PDF, it doesn't save with their Subject titles, just numbers. If I try prints, save as pdf, it consolidates them all into 1 file. If I try to save as txt files, it only saves the first message. If I try dragging and dropping the emails into a folder, it won't let me (only one at a time). Any help would be greatly appreciated.
I believe there is a third party app that saves email(s) as pdf's:
http://www.sperrysoftware.com/Outlook/save-as-pdf.asp?src=googleadwords&gclid=CM aBn9vzu7gCFTMRtAodtjIADg&utm_expid=330330-7.0tmU05zdRNG5j8Zt1v22Dw.0&utm_referre r=http%3A%2F%2Fwww.google.com%2Faclk%3Fsa%3Dl%26ai%3DCYx7OWF_pUbOzJ8GehQewmIBoqo uemQKK4YCxIZPC-aA8CAAQAVDZ7NvS_v____8BYPuh64LoCaAB3rW3_wPIAQGqBChP0BuhRoSOlnh9eX 58SwjbgTHsbaVreSndBi1MKrzUffPlI2monV7nuAYBgAeKykg%26sig%3DAOD64_3QUxRWH7oaxXl2vN SwQqLI_cFtyw%26ved%3D0CDMQ0Qw%26adurl%3Dhttp%3A%2F%2Fwww.SperrySoftware.com%2FOu tlook%2Fsave-as-pdf.asp%253Fsrc%253Dgoogleadwords%26rct%3Dj%26q%3Dsave%2520email s%2520to%2520df -
Save FrameMaker Book as PDF - Files with different page sizes
I've created a book with 2 files - the pages in the first file are 8.5 x 11, the pages in the second file are 8.5 x 14.
How can I save the book as a PDF but keep both page sizes? Right now if I change the page size in the PDF settings dialog, it changes all pages.
Thanks.Something's not right. Try this route then:
1. Use the Print Book option and have the AdobePDF printer instance selected, turn off the the Print to File, enable the "Generate Acrobat Data" option.
2. Click the PDF Setup button to ensure that the Page size is set to the largest (as in the previous message),
3. Then click the Setup... button to configure the printer for the largest size required.
4. Then click the OK button to get back to the Print Book and finally click Print.
5. You should be prompted where to place the file (unless you left the default configuration which may place it on your desktop).
This should have all the pages correctly cropped as in the following sample with Letter, Legal and Tabloid all in one book: -
Generating JNLP file with servlet?
Hi all,
I want to pass in paramters from a hyperlink into a webstart application. Now I know this can be done with webstart 1.5, but using this is not an option for us. What I would like to do is to create a servlet that generates a JNLP file from any parameters passed into it on the hyperlink.
Has anybody done this? Is this possible? would there be any problems with this?
thanks,
JThat's running fine with us. That has been the way for us to transmit authentication information to pass inside the JNLP world.
Be very careful with your output, there's no validation at the client and errors created by wrong JNLPs can be really unpredictable. Do use the DTD to at build time to check the output!
The JNLP file will be downloaded every-time if you output correct headers...
paul -
Itnitialization files with servlets
I just started reading Core Servlets and JSP. I must have missed something. The author explains the use of init files, but what is the purpose of giving values to variables in a seperate file? In the example in the book he sets a string and an integer in an init file. I can understand that you might want that if you have several servlets that use those variables as if they were global variables. I guess in that case I would understand, but can someone tell me why they are used instead of just declairing the variables inside the sevlet itself?
Thanks,
KeithIf yu declare a variable and initiliaze it with a value (hard coding) in the servlet, would you be abe to change its value without re-copmpiling the servet ?
It all about genericity and maintainability.
All such enivronmental information that can potentially change(for example development time versus deployment time) is better put into some kind of properties/configuration/init file.
Maybe you are looking for
-
I just installed the latest security update and now I cannot access iPhoto. I keep getting a message that it quit unexpectedly due to some conflict with the Scene Kit plugin. I'm using a Macbook Pro Mavericks Version 10.9.5
-
Hello's, I've been looking through the forums trying to find an appropriate thread. A co-worker tried to assign an IP address directly to a port on the switchport module in a router. He wasn't able to do so and I was trying to explain to him why so.
-
Displaying a form in a set of accordian panels
The Spry Accordion Panel looks as though it aught to be ideal for inserting a large data records into an on line database. However, this use does not seem to be documented as far as I can see. I wanted to split up the data into sections within the sa
-
Videos not playing. Says it's processing
The videos I recorded on my phone can't play anywhere. They say media not found, can't play video, and that it is processing. I've tried connecting to my laptop, every thing on my phone capable of playing videos and it's not working. I haven't delete
-
Epson 3800 driver options to disable or enable driver rendering disabled
Trying to print from LR 5.3 RC using .icc profile ... in printer settings in Epson Pro 3800 driver the Color Settings and Color drop downs are disabled???? In other applications these options are enabled and selectable.