引发诸如“操作超时”之类的异常

时间:2018-07-31 17:29:21

标签: asp.net oracle-cloud-infrastructure

我正在尝试在oracle云基础架构iaas上上传文件,但是在使用GetRequestStream()写入流时发现诸如操作超时之类的错误。还请检查我尝试发布的文件是否正确。

            FileInfo f = new FileInfo(FileUpload1.FileName);
            byte[] filebyte =FileUpload1.FileBytes;

            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 signer = new RequestSigner(tenancyId, userId, fingerprint, privateKeyPath, privateKeyPassphrase);

           // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var uri = new Uri($"https://objectstorage.us-phoenix-1.oraclecloud.com/");

            var request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "POST";
            request.Accept = "application/json";
            request.SendChunked = true;
            request.ContentType = "text/plain";
             request.KeepAlive = true;
            request.AllowWriteStreamBuffering = false;
            request.ContentLength =postdata.Length;



        try
        {

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

            }
        }
        catch(Exception ex)
        {
            Response.Write("testing"+ex.Message+"Tedting");

        }



            request.Headers["x-content-sha256"] = Convert.ToBase64String(SHA256.Create().ComputeHash(postdata));

1 个答案:

答案 0 :(得分:0)

您需要将URL更新为以下格式:

var uri = new Uri($"https://objectstorage.us-phoenix-1.oraclecloud.com/n/{namespaceName}/b/{bucketName}/o/{objectName}");

文档:https://docs.cloud.oracle.com/iaas/api/#/en/objectstorage/20160918/Object/PutObject

如果您在更新网址后仍然收到错误消息,请编辑问题以包含您遇到的全部错误消息。