上载到Azure存储的文件已损坏

时间:2015-07-30 20:25:04

标签: c# azure azure-storage-blobs

我正在尝试允许用户通过HTML5页面将图像上传到我的网站,并尝试使用Azure Blob存储。我在后端创建了页面和C#代码,但似乎在上传过程中图像被破坏了。我能够拍摄图像并将其传递给Azure,它会创建blob并填充正确大小的图像但是当图像被下载然后打开时我只是得到一堆垃圾(随机字母和符号)而不是图像。任何人都可以帮我解决这个问题,现在已经尝试解决这个问题超过一周了。

[u'Index_15', u'Sentence here with normal spaces and my problem\xa0which I cannot resolve', 60, u'http://www.nicesite.org/Pathway/#Index_15']

链接到从此代码上传的损坏图片:https://gisstore01.blob.core.windows.net/ffinfofiles/ChocoboontheJob/Core/Logo.jpg

2 个答案:

答案 0 :(得分:0)

这就是我用来接受徽标图片......

<asp:Panel ID="submitPanel" runat="server" DefaultButton="submitBTN">
<section class="bg05 well04">
  <div class="container">
    <h2>Application for Enrollment</h2>
    <div class="columns">
    <div class="colLeft"><h4>Select Enrollment Type (select one):</h4></div>
    <div class="colRight">
    <asp:RadioButtonList ID="enrollType" runat="server" RepeatDirection="Horizontal" CssClass="spaced" ValidationGroup="submitApp">
        <asp:ListItem Value="Full-Time">Full-Time</asp:ListItem>
        <asp:ListItem Value="Part-Time">Part-Time</asp:ListItem>
    </asp:RadioButtonList><div class="colAdjust"><asp:RequiredFieldValidator ID="enrollRFV" runat="server" ControlToValidate="enrollType" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" ValidationGroup="submitApp"></asp:RequiredFieldValidator></div>
    </div>
    <br /><br /><br />
    <div class="colGeneral"><asp:Label ID="PriEmailLBL" runat="server" Text="<span class='format'>Primary email address:</span> "></asp:Label></div><div class="colGeneral1"><asp:TextBox ID="PriEmailTXTBOX" runat="server" Width="250px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="PriEmailRFV" runat="server" ControlToValidate="PriEmailTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="PriEmailREV" runat="server" ErrorMessage=" Invalid email address" ControlToValidate="PriEmailTXTBOX" ValidationExpression="[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" Font-Size="Medium" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RegularExpressionValidator></div>
    </div>
  </div>
</section>

<section class="bg02 well02">
  <div class="container">
    <div style="margin-top: 10px;"></div>
    <h4 class="a">Member:</h4><br />
    <div class="colGeneral5"><asp:Label ID="CellLBL" runat="server" Text="<span style='color:White;margin-left:55px;'>Cell #:</span> "></asp:Label><asp:TextBox ID="CellTXTBOX" runat="server" Width="150px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="CellRFV" runat="server" ControlToValidate="CellTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" ValidationGroup="submitApp"></asp:RequiredFieldValidator></div>
    <br />
    <div class="colGeneral5"><asp:Label ID="SecEmailLBL" runat="server" Text="<span style='color:White;'>Secondary Email Address:</span> "></asp:Label><asp:TextBox ID="SecEmailTXTBOX" runat="server" Width="300px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="SecEmailRFV" runat="server" ControlToValidate="SecEmailTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="SecEmailREV" runat="server" ErrorMessage=" Invalid email address" ControlToValidate="SecEmailTXTBOX" ValidationExpression="[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" Font-Size="Medium" ForeColor="White" Display="Dynamic" ValidationGroup="submitApp"></asp:RegularExpressionValidator></div>
    <br /><br />
 <asp:Button ID="submitBTN" runat="server" Text="SUBMIT" OnClick="submitBTN_Click" ValidationGroup="submitApp" />&nbsp;&nbsp;
 <asp:Button ID="resetBTN" runat="server" Text="RESET" CausesValidation="false" ValidationGroup="submitApp" />
 <asp:Label ID="messageLBL" runat="server" Text="" Visible="false"></asp:Label>
 </div>
</section>
</asp:Panel>

这是实际的上传方法

var memoryStream = new MemoryStream();

logoFile.InputStream.CopyTo(memoryStream); //logoFile is HttpPostedFileBase
memoryStream.Position = 0;
await transferService.Upload(memoryStream, fileName, "merchant-app-data", true);

memoryStream.Close();
memoryStream.Dispose();

答案 1 :(得分:0)

您的代码看起来很好。我使用尽可能多的代码做了一个快速原型,看看是否有什么需要注意的,但一切似乎都运行正常。

我的猜测是问题不在于上传本身,而在于对容器的访问。默认情况下,Blob容器不允许公共匿名访问。

为了更改它,更简单的方法是继续使用Visual Studio,通过Server Explorer连接到Azure实例,然后找到Blob容器并单击它。在属性窗口中,您应该看到公共读取访问的条目和三个选项:关闭,容器或Blob。

如果它关闭了,那就是你的问题!根据您的需要选择容器或Blob,尽管选择Blob会更安全。区别在于Blob匿名用户只能访问blob中的数据,但无法访问Blob级别的任何内容,因此,例如,他们无法枚举容器中的所有blob,但他们可以通过blob链接。

如果您想在此处详细了解容器权限,请参阅MSDN链接:https://azure.microsoft.com/en-us/documentation/articles/storage-manage-access-to-resources/

希望这会有所帮助。如果没有,请告诉我们,我们会继续努力。 enter image description here