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