Access issue when uploading file to CloudBlockBlob - Windows Azure
I had to upgrade from Windows Azure 1.7 to 2.1. The only change in code I had
blob.UploadFromFile(tempImage);
to
blob.UploadFromFile(tempImage,FileMode.CreateNew);
However I am getting the following error: "Combining FileMode: CreateNew with FileAccess: Read is invalid."
Here is my code below (I added the "blob.OpenWrite();" just to try). Any ideas why I am getting this error?
string blobUri;
/*var acct = CloudStorageAccount.FromConfigurationSetting("ImagesConnectionString");*/
var setting = CloudConfigurationManager.GetSetting("ImagesConnectionString");
var acct = CloudStorageAccount.Parse(setting);
var blobClient = acct.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName")); //.GetContainerReference("ContainerName");
container.CreateIfNotExists(); //CreateIfNotExist
var perms = container.GetPermissions();
//upload blob image
LocalResource local = RoleEnvironment.GetLocalResource("tempImages");
string tempSlideImage = local.RootPath + mySlideName;
myImage.Save(tempSlideImage);
CloudBlockBlob blob = container.GetBlockBlobReference(myImageName);
blob.Properties.ContentType = "image/jpeg"; //photoToLoad.PostedFile.ContentType; //blob.Properties.ContentType = photoToLoad.PostedFile.ContentType;
blobClient.ParallelOperationThreadCount = 3;
blob.OpenWrite(); //this was added after the migration
blob.UploadFromFile(tempImage,FileMode.CreateNew); //.UploadFile //blob.UploadFromStream(photoToLoad.FileContent);
blobUri = blob.Uri.ToString();
add a comment |
I had to upgrade from Windows Azure 1.7 to 2.1. The only change in code I had
blob.UploadFromFile(tempImage);
to
blob.UploadFromFile(tempImage,FileMode.CreateNew);
However I am getting the following error: "Combining FileMode: CreateNew with FileAccess: Read is invalid."
Here is my code below (I added the "blob.OpenWrite();" just to try). Any ideas why I am getting this error?
string blobUri;
/*var acct = CloudStorageAccount.FromConfigurationSetting("ImagesConnectionString");*/
var setting = CloudConfigurationManager.GetSetting("ImagesConnectionString");
var acct = CloudStorageAccount.Parse(setting);
var blobClient = acct.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName")); //.GetContainerReference("ContainerName");
container.CreateIfNotExists(); //CreateIfNotExist
var perms = container.GetPermissions();
//upload blob image
LocalResource local = RoleEnvironment.GetLocalResource("tempImages");
string tempSlideImage = local.RootPath + mySlideName;
myImage.Save(tempSlideImage);
CloudBlockBlob blob = container.GetBlockBlobReference(myImageName);
blob.Properties.ContentType = "image/jpeg"; //photoToLoad.PostedFile.ContentType; //blob.Properties.ContentType = photoToLoad.PostedFile.ContentType;
blobClient.ParallelOperationThreadCount = 3;
blob.OpenWrite(); //this was added after the migration
blob.UploadFromFile(tempImage,FileMode.CreateNew); //.UploadFile //blob.UploadFromStream(photoToLoad.FileContent);
blobUri = blob.Uri.ToString();
add a comment |
I had to upgrade from Windows Azure 1.7 to 2.1. The only change in code I had
blob.UploadFromFile(tempImage);
to
blob.UploadFromFile(tempImage,FileMode.CreateNew);
However I am getting the following error: "Combining FileMode: CreateNew with FileAccess: Read is invalid."
Here is my code below (I added the "blob.OpenWrite();" just to try). Any ideas why I am getting this error?
string blobUri;
/*var acct = CloudStorageAccount.FromConfigurationSetting("ImagesConnectionString");*/
var setting = CloudConfigurationManager.GetSetting("ImagesConnectionString");
var acct = CloudStorageAccount.Parse(setting);
var blobClient = acct.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName")); //.GetContainerReference("ContainerName");
container.CreateIfNotExists(); //CreateIfNotExist
var perms = container.GetPermissions();
//upload blob image
LocalResource local = RoleEnvironment.GetLocalResource("tempImages");
string tempSlideImage = local.RootPath + mySlideName;
myImage.Save(tempSlideImage);
CloudBlockBlob blob = container.GetBlockBlobReference(myImageName);
blob.Properties.ContentType = "image/jpeg"; //photoToLoad.PostedFile.ContentType; //blob.Properties.ContentType = photoToLoad.PostedFile.ContentType;
blobClient.ParallelOperationThreadCount = 3;
blob.OpenWrite(); //this was added after the migration
blob.UploadFromFile(tempImage,FileMode.CreateNew); //.UploadFile //blob.UploadFromStream(photoToLoad.FileContent);
blobUri = blob.Uri.ToString();
I had to upgrade from Windows Azure 1.7 to 2.1. The only change in code I had
blob.UploadFromFile(tempImage);
to
blob.UploadFromFile(tempImage,FileMode.CreateNew);
However I am getting the following error: "Combining FileMode: CreateNew with FileAccess: Read is invalid."
Here is my code below (I added the "blob.OpenWrite();" just to try). Any ideas why I am getting this error?
string blobUri;
/*var acct = CloudStorageAccount.FromConfigurationSetting("ImagesConnectionString");*/
var setting = CloudConfigurationManager.GetSetting("ImagesConnectionString");
var acct = CloudStorageAccount.Parse(setting);
var blobClient = acct.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName")); //.GetContainerReference("ContainerName");
container.CreateIfNotExists(); //CreateIfNotExist
var perms = container.GetPermissions();
//upload blob image
LocalResource local = RoleEnvironment.GetLocalResource("tempImages");
string tempSlideImage = local.RootPath + mySlideName;
myImage.Save(tempSlideImage);
CloudBlockBlob blob = container.GetBlockBlobReference(myImageName);
blob.Properties.ContentType = "image/jpeg"; //photoToLoad.PostedFile.ContentType; //blob.Properties.ContentType = photoToLoad.PostedFile.ContentType;
blobClient.ParallelOperationThreadCount = 3;
blob.OpenWrite(); //this was added after the migration
blob.UploadFromFile(tempImage,FileMode.CreateNew); //.UploadFile //blob.UploadFromStream(photoToLoad.FileContent);
blobUri = blob.Uri.ToString();
asked Oct 23 '13 at 21:17
xmoreraxmorera
1,16431429
1,16431429
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The 2nd parameter to UploadFromFile (the FileMode) is referring to how you want to open the file on your local machine, not what you want to do with the blob in Azure storage. So to fix you can:
Change
blob.UploadFromFile(tempImage,FileMode.CreateNew);
to
blob.UploadFromFile(tempImage,FileMode.Open);
Also, what is tempImage? You either left out that portion of the code, or it should be tempSlideImage.
Thanks a lot. You are correct that it is tempslideimage. I actually solved it by using a stream
– xmorera
Oct 25 '13 at 16:24
thanks! This got me as well. It makes absolutely no sense that you have to specify the FileMode parameter - when would I ever want it to use anything but FileMode.Read - I can think of only the case where I just want to upload an empty file, then I can tell it to CreateNew
– Simon Ejsing
Nov 12 '13 at 6:54
1
UPDATE: Azure SDK 2.7 with .NET 4.5.1 the following code works blob.UploadFromFile(tempImage,FileMode.Open);
– ProVega
Aug 20 '15 at 16:47
with I could upvote this twice!
– NDJ
Feb 10 '16 at 11:46
@kwill can you check this answer for errors? I don't believe theFileModeenum has ever had a.Readmember; did you meanFileMode.Open?FileAccessis the enum that has.Read
– Caius Jard
Dec 27 '18 at 14:28
|
show 1 more comment
What kwill said will work, however I solved like this:
using (var fileStream = System.IO.File.OpenRead(tempSlideImage))
{
blob.UploadFromStream(fileStream);
}
add a comment |
In my case, the server incorrectly identifies the filename of the HttpPostedFileBase. Thus, load the inputstream, directly.
HttpPostedFileBase file
CloudBlockBlob blob;
.......
using (var fileStream = file.InputStream)
{
blob.UploadFromStream(fileStream);
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19552476%2faccess-issue-when-uploading-file-to-cloudblockblob-windows-azure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The 2nd parameter to UploadFromFile (the FileMode) is referring to how you want to open the file on your local machine, not what you want to do with the blob in Azure storage. So to fix you can:
Change
blob.UploadFromFile(tempImage,FileMode.CreateNew);
to
blob.UploadFromFile(tempImage,FileMode.Open);
Also, what is tempImage? You either left out that portion of the code, or it should be tempSlideImage.
Thanks a lot. You are correct that it is tempslideimage. I actually solved it by using a stream
– xmorera
Oct 25 '13 at 16:24
thanks! This got me as well. It makes absolutely no sense that you have to specify the FileMode parameter - when would I ever want it to use anything but FileMode.Read - I can think of only the case where I just want to upload an empty file, then I can tell it to CreateNew
– Simon Ejsing
Nov 12 '13 at 6:54
1
UPDATE: Azure SDK 2.7 with .NET 4.5.1 the following code works blob.UploadFromFile(tempImage,FileMode.Open);
– ProVega
Aug 20 '15 at 16:47
with I could upvote this twice!
– NDJ
Feb 10 '16 at 11:46
@kwill can you check this answer for errors? I don't believe theFileModeenum has ever had a.Readmember; did you meanFileMode.Open?FileAccessis the enum that has.Read
– Caius Jard
Dec 27 '18 at 14:28
|
show 1 more comment
The 2nd parameter to UploadFromFile (the FileMode) is referring to how you want to open the file on your local machine, not what you want to do with the blob in Azure storage. So to fix you can:
Change
blob.UploadFromFile(tempImage,FileMode.CreateNew);
to
blob.UploadFromFile(tempImage,FileMode.Open);
Also, what is tempImage? You either left out that portion of the code, or it should be tempSlideImage.
Thanks a lot. You are correct that it is tempslideimage. I actually solved it by using a stream
– xmorera
Oct 25 '13 at 16:24
thanks! This got me as well. It makes absolutely no sense that you have to specify the FileMode parameter - when would I ever want it to use anything but FileMode.Read - I can think of only the case where I just want to upload an empty file, then I can tell it to CreateNew
– Simon Ejsing
Nov 12 '13 at 6:54
1
UPDATE: Azure SDK 2.7 with .NET 4.5.1 the following code works blob.UploadFromFile(tempImage,FileMode.Open);
– ProVega
Aug 20 '15 at 16:47
with I could upvote this twice!
– NDJ
Feb 10 '16 at 11:46
@kwill can you check this answer for errors? I don't believe theFileModeenum has ever had a.Readmember; did you meanFileMode.Open?FileAccessis the enum that has.Read
– Caius Jard
Dec 27 '18 at 14:28
|
show 1 more comment
The 2nd parameter to UploadFromFile (the FileMode) is referring to how you want to open the file on your local machine, not what you want to do with the blob in Azure storage. So to fix you can:
Change
blob.UploadFromFile(tempImage,FileMode.CreateNew);
to
blob.UploadFromFile(tempImage,FileMode.Open);
Also, what is tempImage? You either left out that portion of the code, or it should be tempSlideImage.
The 2nd parameter to UploadFromFile (the FileMode) is referring to how you want to open the file on your local machine, not what you want to do with the blob in Azure storage. So to fix you can:
Change
blob.UploadFromFile(tempImage,FileMode.CreateNew);
to
blob.UploadFromFile(tempImage,FileMode.Open);
Also, what is tempImage? You either left out that portion of the code, or it should be tempSlideImage.
edited Dec 30 '18 at 4:04
answered Oct 24 '13 at 4:30
kwillkwill
9,35112123
9,35112123
Thanks a lot. You are correct that it is tempslideimage. I actually solved it by using a stream
– xmorera
Oct 25 '13 at 16:24
thanks! This got me as well. It makes absolutely no sense that you have to specify the FileMode parameter - when would I ever want it to use anything but FileMode.Read - I can think of only the case where I just want to upload an empty file, then I can tell it to CreateNew
– Simon Ejsing
Nov 12 '13 at 6:54
1
UPDATE: Azure SDK 2.7 with .NET 4.5.1 the following code works blob.UploadFromFile(tempImage,FileMode.Open);
– ProVega
Aug 20 '15 at 16:47
with I could upvote this twice!
– NDJ
Feb 10 '16 at 11:46
@kwill can you check this answer for errors? I don't believe theFileModeenum has ever had a.Readmember; did you meanFileMode.Open?FileAccessis the enum that has.Read
– Caius Jard
Dec 27 '18 at 14:28
|
show 1 more comment
Thanks a lot. You are correct that it is tempslideimage. I actually solved it by using a stream
– xmorera
Oct 25 '13 at 16:24
thanks! This got me as well. It makes absolutely no sense that you have to specify the FileMode parameter - when would I ever want it to use anything but FileMode.Read - I can think of only the case where I just want to upload an empty file, then I can tell it to CreateNew
– Simon Ejsing
Nov 12 '13 at 6:54
1
UPDATE: Azure SDK 2.7 with .NET 4.5.1 the following code works blob.UploadFromFile(tempImage,FileMode.Open);
– ProVega
Aug 20 '15 at 16:47
with I could upvote this twice!
– NDJ
Feb 10 '16 at 11:46
@kwill can you check this answer for errors? I don't believe theFileModeenum has ever had a.Readmember; did you meanFileMode.Open?FileAccessis the enum that has.Read
– Caius Jard
Dec 27 '18 at 14:28
Thanks a lot. You are correct that it is tempslideimage. I actually solved it by using a stream
– xmorera
Oct 25 '13 at 16:24
Thanks a lot. You are correct that it is tempslideimage. I actually solved it by using a stream
– xmorera
Oct 25 '13 at 16:24
thanks! This got me as well. It makes absolutely no sense that you have to specify the FileMode parameter - when would I ever want it to use anything but FileMode.Read - I can think of only the case where I just want to upload an empty file, then I can tell it to CreateNew
– Simon Ejsing
Nov 12 '13 at 6:54
thanks! This got me as well. It makes absolutely no sense that you have to specify the FileMode parameter - when would I ever want it to use anything but FileMode.Read - I can think of only the case where I just want to upload an empty file, then I can tell it to CreateNew
– Simon Ejsing
Nov 12 '13 at 6:54
1
1
UPDATE: Azure SDK 2.7 with .NET 4.5.1 the following code works blob.UploadFromFile(tempImage,FileMode.Open);
– ProVega
Aug 20 '15 at 16:47
UPDATE: Azure SDK 2.7 with .NET 4.5.1 the following code works blob.UploadFromFile(tempImage,FileMode.Open);
– ProVega
Aug 20 '15 at 16:47
with I could upvote this twice!
– NDJ
Feb 10 '16 at 11:46
with I could upvote this twice!
– NDJ
Feb 10 '16 at 11:46
@kwill can you check this answer for errors? I don't believe the
FileMode enum has ever had a .Read member; did you mean FileMode.Open? FileAccess is the enum that has .Read– Caius Jard
Dec 27 '18 at 14:28
@kwill can you check this answer for errors? I don't believe the
FileMode enum has ever had a .Read member; did you mean FileMode.Open? FileAccess is the enum that has .Read– Caius Jard
Dec 27 '18 at 14:28
|
show 1 more comment
What kwill said will work, however I solved like this:
using (var fileStream = System.IO.File.OpenRead(tempSlideImage))
{
blob.UploadFromStream(fileStream);
}
add a comment |
What kwill said will work, however I solved like this:
using (var fileStream = System.IO.File.OpenRead(tempSlideImage))
{
blob.UploadFromStream(fileStream);
}
add a comment |
What kwill said will work, however I solved like this:
using (var fileStream = System.IO.File.OpenRead(tempSlideImage))
{
blob.UploadFromStream(fileStream);
}
What kwill said will work, however I solved like this:
using (var fileStream = System.IO.File.OpenRead(tempSlideImage))
{
blob.UploadFromStream(fileStream);
}
answered Oct 25 '13 at 16:25
xmoreraxmorera
1,16431429
1,16431429
add a comment |
add a comment |
In my case, the server incorrectly identifies the filename of the HttpPostedFileBase. Thus, load the inputstream, directly.
HttpPostedFileBase file
CloudBlockBlob blob;
.......
using (var fileStream = file.InputStream)
{
blob.UploadFromStream(fileStream);
}
add a comment |
In my case, the server incorrectly identifies the filename of the HttpPostedFileBase. Thus, load the inputstream, directly.
HttpPostedFileBase file
CloudBlockBlob blob;
.......
using (var fileStream = file.InputStream)
{
blob.UploadFromStream(fileStream);
}
add a comment |
In my case, the server incorrectly identifies the filename of the HttpPostedFileBase. Thus, load the inputstream, directly.
HttpPostedFileBase file
CloudBlockBlob blob;
.......
using (var fileStream = file.InputStream)
{
blob.UploadFromStream(fileStream);
}
In my case, the server incorrectly identifies the filename of the HttpPostedFileBase. Thus, load the inputstream, directly.
HttpPostedFileBase file
CloudBlockBlob blob;
.......
using (var fileStream = file.InputStream)
{
blob.UploadFromStream(fileStream);
}
answered Jan 17 '14 at 23:13
1c1cle1c1cle
35525
35525
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19552476%2faccess-issue-when-uploading-file-to-cloudblockblob-windows-azure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown