Я попытался запустить. NET код, который был упомянут в опубликованном c документе AWS. Тем не менее, я в конечном итоге с ошибками ниже 2.
HttpErrorResponseException: удаленный сервер возвратил ошибку: (405) Метод не разрешен. Amazon.WorkDocs.Model.InvalidOperationException: 'InvalidOperationException: неверный запрос операции. Не удалось найти физический файл для версии документа с идентификатором
WebException: удаленный сервер возвратил ошибку: (405) Метод не разрешен. Amazon.WorkDocs.Model.InvalidOperationException: 'InvalidOperationException: неверный запрос операции. Не удалось найти физический файл для версии документа с идентификатором
AWS URL-адрес документа: - https://docs.aws.amazon.com/code-samples/latest/catalog/code-catalog-dotnet-example_code-WorkDocs-workdocssample1.html
using System;
using System.Collections.Generic;
using System.Net;
using Amazon;
using Amazon.WorkDocs;
using Amazon.WorkDocs.Model;
namespace WorkdocsSample1
{
class UploadUserDocs
{
private static String GetUserFolderId(AmazonWorkDocsClient wdClient, String orgId, String user)
{
var wdDescribeUsersRequest = new DescribeUsersRequest()
{
Marker = null,
OrganizationId = orgId,
Query = user
};
var wdDescribeUsersResponse = wdClient.DescribeUsers(wdDescribeUsersRequest);
// Return the first matching user root folder id
if (wdDescribeUsersResponse.Users.Count > 0)
return wdDescribeUsersResponse.Users[0].RootFolderId;
return String.Empty;
}
private static Dictionary<String, String> GetDocumentUploadInfo(AmazonWorkDocsClient wdClient, String orgId, String user, String docName)
{
String folderId = GetUserFolderId(wdClient, orgId, user);
var request = new InitiateDocumentVersionUploadRequest()
{
Name = docName,
ParentFolderId = folderId,
ContentType = "application/octet-stream"
};
var result = wdClient.InitiateDocumentVersionUpload(request);
var documentInfoMap = new Dictionary<String, String>();
documentInfoMap.Add("documentId", result.Metadata.Id);
documentInfoMap.Add("versionId", result.Metadata.LatestVersionMetadata.Id);
documentInfoMap.Add("uploadURL", result.UploadMetadata.UploadUrl);
return documentInfoMap;
}
public static void Sample()
{
// Based on WorkDocs dev guide code at http://docs.aws.amazon.com/workdocs/latest/developerguide/connect-workdocs-role.html
var wdClient = new AmazonWorkDocsClient(awsAccessKeyId: "xxxxxxxx", awsSecretAccessKey: "xxxxxxx", region: RegionEndpoint.USEast1);
String orgId = "d-9xxxxxx"; // Directory
String userEmail = "iamsmart@gmail.com"; // WorkDocs user mail id
String workdocsName = "abc";
String uploadDocFullName = "C:\\test.txt";
var docInfo = GetDocumentUploadInfo(wdClient, orgId, userEmail, workdocsName);
if (docInfo.Count > 0)
{
String documentId = docInfo["documentId"];
String versionId = docInfo["versionId"];
String uploadURL = docInfo["uploadURL"];
if (!String.IsNullOrEmpty(documentId) && !String.IsNullOrEmpty(versionId))
{
try
{
using (var client = new WebClient())
//WebClient client = new WebClient();
client.UploadFile(uploadURL, "POST", uploadDocFullName);
}
catch (WebException ex)
{
Console.WriteLine(ex.ToString());
}
var request = new UpdateDocumentVersionRequest()
{
DocumentId = documentId,
VersionId = versionId,
VersionStatus = DocumentVersionStatus.ACTIVE
};
wdClient.UpdateDocumentVersion(request);
}
else
Console.WriteLine("Could not get info about workdoc {0}", workdocsName);
}
else
Console.WriteLine("Could not get info about workdoc {0}", workdocsName);
}
}
}