How to upload files into azure blob storage using java

                       HOW TO UPLOAD FILES INTO AZURE BLOB USING JAVA

  • First, create the CloudStorageAccount object using the STORAGE_CONNECTION_STRING(AccountName and Account Key).
  • Create the serviceClient using the CloudStorageAccount object.
  • Using the service client object to create the container.
  • Using the upload from file method to upload the file into Azure container.
File Upload Process in azure

import com.microsoft.azure.storage.CloudStorageAccount; import com.microsoft.azure.storage.StorageException; import com.microsoft.azure.storage.blob.CloudBlobClient; import com.microsoft.azure.storage.blob.CloudBlobContainer; import com.microsoft.azure.storage.blob.CloudBlockBlob; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.security.InvalidKeyException; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Janardhan Randhi * * Date : Feb 4 2019 * * Description : This class uploads files from local Test to the azure blob storage container. * * */ public class AzureBlobFileUpload { public static final String STORAGE_CONNECTION_STRING = "DefaultEndpointsProtocol=https;" + "AccountName=Ram;" + "AccountKey=key"; private static final Logger LOGGER = Logger.getLogger(AzureBlobFileUpload.class.getName()); public static void main(String[] args) throws URISyntaxException, StorageException, InvalidKeyException, IOException { AzureBlobFileUpload ab = new AzureBlobFileUpload(); ab.uploadFile(new File(args[0])); } public void uploadFile(File file) throws URISyntaxException, StorageException, InvalidKeyException, IOException { try { CloudStorageAccount account = CloudStorageAccount.parse(STORAGE_CONNECTION_STRING); CloudBlobClient serviceClient = account.createCloudBlobClient(); // Container name must be lower case. CloudBlobContainer container = serviceClient.getContainerReference("Janardhan"); container.createIfNotExists(); CloudBlockBlob blob = container.getBlockBlobReference(file.getName()); blob.uploadFromFile(file.getAbsolutePath()); System.out.println("File uploaded successfully"); //new File( file.getName()).delete(); //deleting files from local system. } catch (StorageException | IOException | URISyntaxException | InvalidKeyException exception) { LOGGER.log(Level.SEVERE, exception.getMessage()); System.exit(-1); } } }

SUBSCRIBE TO OUR NEWSLETTER

I’m the Founder of quickdevops.com. I am a Professional Blogger, Application developer, YouTuber. I’ve been blogging since 2015.I spend a lot of time learning new techniques and actively help other people learn web development through a variety of help groups and writing web development tutorials for my website and blog about advancements in web design and development.Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie or planning a trip to someplace I've never been before.

14 Responses to "How to upload files into azure blob storage using java "

  1. Why post a blog if you dont let your readers copy your code?

    ReplyDelete
  2. https://www.omgqq.com 우리카지노사이트
    https://www.omgqq.com/thekingcasino 더킹카지노
    https://www.omgqq.com/sandscasino 샌즈카지노
    https://www.omgqq.com/firstcasino 퍼스트카지노
    https://www.omgqq.com/yescasino 예스카지노
    https://www.omgqq.com/supercasino 슈퍼카지노
    https://www.omgqq.com/gatsbycasino 개츠비카지노
    https://www.omgqq.com/33casino 33카지노
    https://www.omgqq.com/worldcasino 월드카지노
    https://www.omgqq.com/merit 메리트카지노

    ReplyDelete
  3. NAS is a kind of document storage gadget that interfaces with an organization. NAS gadgets, which commonly don't have a console or show, give Local Area Network (LAN) hubs with document storage through a standard Ethernet association. Fuel Bladder Tanks manufacturer

    ReplyDelete
  4. A big thank you for your post. Really thank you! Cool.
    tap storage singapore

    ReplyDelete
  5. Machos Gracias for your blog post. Really looking forward to read more. Fantastic.
    check more info about tape storage

    ReplyDelete
  6. Serial Advanced Technology Attachment (SATA), eSATA, Small Computer System Interface (SCSI), Serial Attached SCSI (SAS), and Fiber Channel.
    cheap website hosting

    ReplyDelete
  7. Thank You to give me a solutions.


    If You Want to Get Discount on Shopping So Check Our Store:
    smartbuyglasses promo code

    ReplyDelete
  8. If you want to save a large amount of your money then click the link. So, visit here yoshinoya discount code

    ReplyDelete
  9. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. tape storage

    ReplyDelete
  10. I really like the good articles here

    ReplyDelete
  11. If you want to save a large amount of your money then click the link and make a joyful future for you.
    Kyte Baby shipping coupon

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete