在oracle云基础架构上上传文档时服务器返回错误404

时间:2018-08-03 11:23:18

标签: oracle-cloud-infrastructure

我可以使用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);

1 个答案:

答案 0 :(得分:0)

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