我正在尝试使用 api 将图像上传到我的个人资料,但出现 Unknown: NOT_FOUND 404 错误。我正在使用的调用是/d2l/api/lp/1.0/profile/myProfile/image,我正在传递内容类型、长度和文件名(profileImage)。我将图像作为数据流传递。我也缩小了图像的大小。有任何想法吗?
这里也是我的 CallAction 代码的一部分,最初是从 Getting Started 示例中获得的
public void CallAction(ID2LUserContext userContext, int retryAttempts, string url, byte[] data, string method = "")
{
Uri uri = userContext.CreateAuthenticatedUri(url, method);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.AllowAutoRedirect = false;
request.Method = method;
if (method.Equals("PUT") || method.Equals("POST"))
{
request.ContentType = "image/jpeg";
//request.Headers.Add("Content-Disposition", "form-data; name=\"profileImage\"; filename=\"profileImage.jpg\"");
request.Headers.Add("Accept-Encoding", "gzip, deflate, compress");
//request.Headers.Add("X-Upload-Content-Type", "image/jpg");
//request.Headers.Add("X-Upload-Content-Length", data.Length.ToString());
//request.Headers.Add("X-Upload-File-Name", "profileImage");
request.ContentLength = data.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Flush();
dataStream.Close();
}
}
此外,当我运行 get 来检索我的照片时,它也会返回 404 错误。