Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to upload an image to a blob in Azure?
    primarykey
    data
    text
    <p>The problem with the code I use is that the file appears in the blob, but as a 0B size file. As if no data was written to the blob.</p> <p>This is the form I use in my JSP:</p> <pre><code>&lt;form method="POST" action="UploadServlet" enctype="multipart/form-data" &gt; &lt;input type="file" name="file" id="file" /&gt; &lt;br/&gt; &lt;/br&gt; &lt;input type="submit" value="Upload" name="upload" id="upload" /&gt; &lt;/form&gt; </code></pre> <p>And I have the following code in my servlet:</p> <pre><code> try { CloudStorageAccount account; CloudBlobClient serviceClient; CloudBlobContainer container; CloudBlockBlob blob; account = CloudStorageAccount.parse(storageConnectionString); serviceClient = account.createCloudBlobClient(); container = serviceClient.getContainerReference("gettingstarted"); container.createIfNotExist(); // Set anonymous access on the container. BlobContainerPermissions containerPermissions; containerPermissions = new BlobContainerPermissions(); containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); container.uploadPermissions(containerPermissions); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload fileUpload = new ServletFileUpload(factory); //process only if its multipart content InputStream is = null; if (ServletFileUpload.isMultipartContent(request)) { List items = fileUpload.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { is = item.getInputStream(); String name = new File(item.getName()).getName(); System.out.println(name); blob = container.getBlockBlobReference(name); File fileReference = new File(item.getName()); System.out.println(is); blob.upload(is, fileReference.length()); } } } is.close(); request.getRequestDispatcher("hello").forward(request, response); } catch (Exeption e) { } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload