我正在尝试从存储桶中删除一个对象。阅读文档听起来非常简单,但我似乎无法让它工作。在服务器端,我在 ASP.NET 中有以下内容:
[HttpDelete]
[Route("api/forge/oss/objects/delete")]
public async Task<dynamic> DeleteObject_fromBucket()
{
// basic input validation
HttpRequest req = HttpContext.Current.Request;
if (string.IsNullOrWhiteSpace(req.Params["bucketKey"]))
throw new System.Exception("BucketKey parameter was not provided.");
if (string.IsNullOrWhiteSpace(req.Params["objectName"]))
throw new System.Exception("ObjectName parameter was not provided.");
string bucketKey = req.Params["bucketKey"];
string objectName = req.Params["objectName"];
// call API to delete object on the bucket
dynamic oauth = await OAuthController.GetInternalAsync();
ObjectsApi objects = new ObjectsApi();
string access_token = oauth.access_token; ;
objects.Configuration.AccessToken = access_token;
// delete the file/object
await objects.DeleteObjectAsync(bucketKey, objectName);
return 0;
}
客户端:
function deleteObject(node) {
result = window.confirm('Wollen Sie dieses Modell löschen');
if (result == false) { return; }
else {
var bucketKey = node.parents[0];
var objectName = node.text;
var formData = new FormData();
formData.append('bucketKey', bucketKey);
formData.append('objectName', objectName);
$.ajax({
url: 'api/forge/oss/objects/delete',
data: formData,
contentType: false,
processData: false,
type: 'DELETE', // man könnte auch method: schreiben
success: function (data) {
$('#appBuckets').jstree(true).refresh_node(node);
}
});
}
}
我总是遇到无法进行 API 调用的异常。bucketKey 和 objectName 都是字符串。谁能帮我理解我哪里出错了?
非常感谢。