First of all in my web.config
I added the code :
<appSettings>
<add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
</appSettings>
And I created the Containers and as you can see, it's public :
And the code to upload. The same code works but with a Azure Account, but not with the Emulator!
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("imagesproducts");
var resultList = JsonConvert.DeserializeObject<List<string>>(Images);
var urlsList = new List<String>();
for(int i = 0; i < resultList.Count; i++)
{
byte[] singleImage = String.IsNullOrEmpty(resultList[i])? null : System.Convert.FromBase64String(resultList[i]);
CloudBlockBlob block = container.GetBlockBlobReference(Guid.NewGuid().ToString() + ".jpg");
using (var stream = new MemoryStream(singleImage, writable: false))
{
await block.UploadFromStreamAsync(stream);
}
urlsList.Add(block.Uri.AbsolutePath);
}
return JsonConvert.SerializeObject(urlsList);
And I always get a Exception of The remote server returned an error: (400) Bad Request
.
I know this is an older thread, but a few findings I had while researching similar issues that might save others time:
1) Make sure the Azure Storage Emulator connection string is parsing out to show the localhost IP endpoints and not the default Azure endpoints.
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1; AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;
2) Container names will cause this issue. There are specific naming rules for containers.
A container name must be a valid DNS name, conforming to the following naming rules:
- Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.
- Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.
- All letters in a container name must be lowercase.
- Container names must be from 3 through 63 characters long.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.