Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 825685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:17:44+00:00 2026-05-15T03:17:44+00:00

When I upload an image file to a blob, the image is uploaded apparently

  • 0

When I upload an image file to a blob, the image is uploaded apparently successfully (no errors). When I go to cloud storage studio, the file is there, but with a size of 0 (zero) bytes.

The following is the code that I am using:

// These two methods belong to the ContentService class used to upload
// files in the storage.
public void SetContent(HttpPostedFileBase file, string filename, bool overwrite)
{
    CloudBlobContainer blobContainer = GetContainer();
    var blob = blobContainer.GetBlobReference(filename);

    if (file != null)
    {
        blob.Properties.ContentType = file.ContentType;
        blob.UploadFromStream(file.InputStream);
    }
    else
    {
        blob.Properties.ContentType = "application/octet-stream";
        blob.UploadByteArray(new byte[1]);
    }
}

public string UploadFile(HttpPostedFileBase file, string uploadPath)
{
    if (file.ContentLength == 0)
    {
        return null;
    }

    string filename;
    int indexBar = file.FileName.LastIndexOf('\\');
    if (indexBar > -1)
    {
        filename = DateTime.UtcNow.Ticks + file.FileName.Substring(indexBar + 1);
    }
    else
    {
        filename = DateTime.UtcNow.Ticks + file.FileName;
    }
    ContentService.Instance.SetContent(file, Helper.CombinePath(uploadPath, filename), true);
    return filename;
}

// The above code is called by this code.
HttpPostedFileBase newFile = Request.Files["newFile"] as HttpPostedFileBase;
ContentService service = new ContentService();
blog.Image = service.UploadFile(newFile, string.Format("{0}{1}", Constants.Paths.BlogImages, blog.RowKey));

Before the image file is uploaded to the storage, the Property InputStream from the HttpPostedFileBase appears to be fine (the size of the of image corresponds to what is expected! And no exceptions are thrown).

And the really strange thing is that this works perfectly in other cases (uploading Power Points or even other images from the Worker role). The code that calls the SetContent method seems to be exactly the same and file seems to be correct since a new file with zero bytes is created at the correct location.

Does any one have any suggestion please? I debugged this code dozens of times and I cannot see the problem. Any suggestions are welcome!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:17:44+00:00Added an answer on May 15, 2026 at 3:17 am

    The Position property of the InputStream of the HttpPostedFileBase had the same value as the Length property (probably because I had another file previous to this one – stupid I think!).

    All I had to do was to set the Position property back to 0 (zero)!

    I hope this helps somebody in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's ok to upload image in file using codeigniter upload library with this example.
I am trying to upload a file via a form and then save in
The directory and file structure is as follows: C:\xampp\htdocs\PHP_Upload_Image_MKDIR\uploaded C:\xampp\htdocs\testA.php // as follows $userID
I'm writing an image file uploader for android for my favorite image gallery software
I am trying to do something quite simple using Sinatra and RMagick . Take
My current directory structure is as follows: C:\xampp\htdocs\PHP_Upload_Image_MKDIR In other words, the following directories
I've noticed in Kohana 3 these error messages provided by default. return array( 'not_empty'
I have a PHP form that is inserting information into a database. It all
We currently have SVN set up as the source control repository to track changes
I have been tasked with building a simple web based system for managing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.