0

我可以使用 Oracle 云基础设施的 API 列出存储桶的对象。但是当我尝试上传文件时,它显示错误 404。我不确定 URI 是否正确或我没有被授权。

这里的代码片段:

            FileInfo f = new FileInfo(FileUpload1.FileName);
            byte[] filebyte =FileUpload1.FileBytes;
            var myfirstobject = FileUpload1.FileName;
            Response.Write(myfirstobject);
            var postdata = Encoding.UTF8.GetBytes(filebyte.ToString());

            var tenancyId = ConfigurationManager.AppSettings["BMCTenancyId"];
            var userId = ConfigurationManager.AppSettings["BMCUserId"];
            var fingerprint = ConfigurationManager.AppSettings["BMCFingerprint"];
            var privateKeyPath = ConfigurationManager.AppSettings["BMCPrivateKeyPath"];
            var privateKeyPassphrase = ConfigurationManager.AppSettings["BMCPrivateKeyPassphrase"];
            var bucket= ConfigurationManager.AppSettings["BMCBucket"];
            var Namespace= ConfigurationManager.AppSettings["BMCNamespace"];

            var signer = new RequestSigner(tenancyId, userId, fingerprint, privateKeyPath, privateKeyPassphrase);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var uri = new Uri($"https://objectstorage.us-phoenix-1.oraclecloud.com/n/{Namespace}/b/{bucket}/{myobject}");

            var request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "PUT";
           request.ContentType = "application/json";
          request.ContentLength = postdata.Length;
        request.Headers["x-content-sha256"] = Convert.ToBase64String(SHA256.Create().ComputeHash(bytes));

        using (var stream = request.GetRequestStream())
        {
            stream.Write(bytes, 0, bytes.Length);
        }

        signer.SignRequest(request);


        ExecuteRequest(request);
4

1 回答 1

0

您是否可以从 OCI 控制台执行相同的操作,使用与上面代码 ( ) 中使用的用户相同的用户BMCUserId?如果不是,那么您无权执行该操作,并且这不是您的代码的问题。否则,这是您的代码的问题。

于 2018-08-07T18:14:21.380 回答