Get a URL for a Resource

I am working on a generator of pdf with flying saucer and i need to have access to a url in order to display an image.
As file resources can not be retrieved by a regular URL from the server i tried to store the image in temporary folder and get the url of this temporary image.
I am not sure of how to achieve that. I tried to use java createTempFile but it doesn’t store the temp file online.

Here is what i tried.

						URI uriSchema = new URI(previousImageField.getSingleData(String.class));
						File schema = (localStorageService.getFile(uriSchema)
						BufferedImage img =;
						File schemaTemp = File.createTempFile("schema",".png");
                        schemaTempPath = schemaTemp.getAbsolutePath();

Thanks a lot,

You need to create a Resource. So there are two possibilities:

  1. write the image to byte output stream:
		final ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
		return new StreamResource(new StreamSource() {

			public InputStream getStream() {
				return new ByteArrayInputStream(output.toByteArray());
		}, "document.doc");
  1. or to temporary file:[code]
    File tmpFile = File.createTempFile(“document”, “.doc”);
    try {;
    } catch (Docx4JException e) {
    throw new IOException(e);
    return new FileResource(tmpFile);