小编Dav*_*ora的帖子

无法使用Azure的REST API创建Blob容器

我正在尝试使用C#和REST API(在Xamarin.Android中)创建一个Blob容器.我能够将blob上传到现有容器,但我似乎无法通过REST创建容器.错误是(403)服务器无法验证请求.确保正确形成Authorization标头的值,包括签名. 创建授权标题在上传blob时起作用,所以它必须是我正在构建要签名的容器字符串的方式,但对于我的生活,我找不到问题.这是代码:

    private async Task<bool> CreateContainer(string containerName)
    {          
        String requestMethod = "PUT";
        String msVersion = "2009-09-19";
        string dt = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);

        String canonicalizedHeaders = String.Format("x-ms-date:{0}\nx-ms-version:{1}", dt, msVersion);
        String canonicalizedResource = String.Format("/{0}/{1}\nrestype:container", AzureStorageConstants.Account, containerName);
        String stringToSign = String.Format("{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}\n{2}", requestMethod, canonicalizedHeaders, canonicalizedResource);

        string auth = SignThis(stringToSign);   
        string urlPath = string.Format("https://{0}.blob.core.windows.net/{1}?restype=container", AzureStorageConstants.Account, containerName);
        Uri uri = new Uri(urlPath);

        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Add("x-ms-date", dt);
        client.DefaultRequestHeaders.Add("x-ms-version", "2009-09-19");
        client.DefaultRequestHeaders.Add("Authorization", auth);

        HttpContent empty = null;
        HttpResponseMessage response = await client.PutAsync(uri, empty);

        return response.IsSuccessStatusCode; …
Run Code Online (Sandbox Code Playgroud)

c# rest azure azure-storage-blobs xamarin

3
推荐指数
1
解决办法
930
查看次数

如何使用 React ExpoSharing.shareAsync 分享本地照片?

我正在尝试使用 React Expo 共享本地文件Sharing.shareAsync()。使用MediaLibrary.getAssetInfoAsync()(在 Android 上)检索照片信息:

"filename": "IMG_20200414_190459.jpg",
  "height": 2074,
  "id": "896",
  "localUri": "file:///storage/emulated/0/DCIM/Camera/IMG_20200414_190459.jpg",
  "location": null,
  "mediaType": "photo",
  "modificationTime": 1586905500000,
  "uri": "file:///storage/emulated/0/DCIM/Camera/IMG_20200414_190459.jpg",
  "width": 4608,
Run Code Online (Sandbox Code Playgroud)

打电话Sharing.shareAsync(photo.localUri, {mimeType: 'image/jpeg'}我得到错误Failed to share the file: Failed to find configured root that contains /storage/emulated/0/DCIM/Camera/IMG_20200414_190459.jpg。所以我尝试删除后面的斜杠之一file:并收到错误Not allowed to read file under given URL.

应用程序具有CAMERA_ROLL权限CAMERA,app.json 包括:

"android": {
      "permissions": [
        "CAMERA",
        "CAMERA_ROLL",
        "READ_EXTERNAL_STORAGE",
        "WRITE_EXTERNAL_STORAGE"
      ]
    }
Run Code Online (Sandbox Code Playgroud)

世博文档说我应该能够共享本地文件。不确定我做错了什么或下一步要尝试什么。TIA。

react-native expo

0
推荐指数
1
解决办法
2688
查看次数

标签 统计

azure ×1

azure-storage-blobs ×1

c# ×1

expo ×1

react-native ×1

rest ×1

xamarin ×1