none
What's the FileMode for on CloudBlockBlob.UploadFromFileAsync?

    Question

  • In the Azure Storage API (2.1), the CloudBlockBlob class's UploadFromFileAsync method takes a FileMode (on all the various overloads). Why would you ever use anything other than FileMode.Open on this?

    The other modes (Append, Create, CreateNew, OpenOrCreate, and Truncate) are all for scenarios where you're going to write to the file. But UploadFromFileAsync uploads an existing file's contents to blob storage, and the file has to exist and already have the content you want at the point at which you call this API. So I can't see any reason you'd use any of those other modes.

    But presumably this argument is there for a reason, so I must be missing something. Can anyone tell me what?

    Tuesday, December 31, 2013 8:26 AM

Answers

All replies

  • Hi,
    The parameter of FileMode is a constant that determines how to open the file, this paremeter just from FileMode class, He had had other parameters, but in UploadFromFileAsync method we upload file to blob, first, we need a target, and just as you said "the file has to exist and already have the content", from my experience, the "Open" mode is suitable for us, I agree with your opinion.
    Regards

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 31, 2013 9:29 AM
    Moderator
  • UploadFromFile is a wrapper on top of UploadFromStream by simply creating a FileStream object. Hence, we provided the same option that FileStream provides, but most of the time, Open is the only useful choice as you also mentioned. If, however, you want to still upload an empty file if the file does not exist, OpenOrCreate is also a viable option.
    Tuesday, December 31, 2013 7:17 PM
  • Hmm... Uploading an empty file seems like a post hoc rationalization. Moreover, it's not a very good reason: if you wanted to upload an empty blob it'd be easier just to use UploadFromByteArray or UploadFromStream. Using the file-oriented API requires you to decide on a location for the file and to delete it afterwards, making this an unnecessarily complicated way of uploading an empty blob.
    Wednesday, January 1, 2014 12:22 PM
  • Thank you for your feedback. We will consider it for future releases.
    • Edited by Serdar Ozler [MSFT] Wednesday, January 1, 2014 8:35 PM
    • Marked as answer by IanG Thursday, January 2, 2014 7:47 AM
    Wednesday, January 1, 2014 8:35 PM