Пример #1
0
 public void UploadVoiceMessageDocument(Stream stream, List <int> waveform, Action <BackendResult <Doc, ResultCode> > callback, Action <double> progressCallback = null, Cancellation cancellation = null)
 {
     DocumentsService.GetDocumentUploadServer(0, "audio_message", (Action <BackendResult <VKClient.Audio.Base.UploadServerAddress, ResultCode> >)(uploadUrlResponse =>
     {
         if (uploadUrlResponse.ResultCode == ResultCode.Succeeded)
         {
             JsonWebRequest.UploadVoiceMessage(uploadUrlResponse.ResultData.upload_url, stream, "file", "file", waveform, (Action <JsonResponseData>)(jsonResult =>
             {
                 if (jsonResult.IsSucceeded)
                 {
                     UploadDocResponseData uploadData = JsonConvert.DeserializeObject <UploadDocResponseData>(jsonResult.JsonString);
                     if (string.IsNullOrEmpty(uploadData.error))
                     {
                         DocumentsService.SaveDocument(uploadData, callback);
                     }
                     else
                     {
                         callback(new BackendResult <Doc, ResultCode>(ResultCode.UnknownError));
                     }
                 }
                 else
                 {
                     callback(new BackendResult <Doc, ResultCode>(ResultCode.UnknownError));
                 }
             }), "Voice Message", progressCallback, cancellation);
         }
         else
         {
             callback(new BackendResult <Doc, ResultCode>(uploadUrlResponse.ResultCode));
         }
     }));
 }
Пример #2
0
 public void UploadGraffitiDocument(string fileName, string fileExtension, Stream stream, Action <BackendResult <Doc, ResultCode> > callback, Action <double> progressCallback = null, Cancellation cancellation = null)
 {
     DocumentsService.GetDocumentUploadServer(0, "graffiti", (Action <BackendResult <VKClient.Audio.Base.UploadServerAddress, ResultCode> >)(uploadUrlResponse =>
     {
         if (uploadUrlResponse.ResultCode == ResultCode.Succeeded)
         {
             string uploadUrl                  = uploadUrlResponse.ResultData.upload_url;
             string str                        = fileName.EndsWith(fileExtension) ? fileName : fileName + fileExtension;
             Stream data                       = stream;
             string paramName                  = "file";
             string uploadContentType          = "file";
             string fileName1                  = str;
             Action <double> progressCallback1 = progressCallback;
             Cancellation c                    = cancellation;
             JsonWebRequest.Upload(uploadUrl, data, paramName, uploadContentType, (Action <JsonResponseData>)(jsonResult =>
             {
                 if (jsonResult.IsSucceeded)
                 {
                     UploadDocResponseData uploadData = JsonConvert.DeserializeObject <UploadDocResponseData>(jsonResult.JsonString);
                     if (string.IsNullOrEmpty(uploadData.error))
                     {
                         DocumentsService.SaveDocument(uploadData, callback);
                     }
                     else
                     {
                         callback(new BackendResult <Doc, ResultCode>(ResultCode.UnknownError));
                     }
                 }
                 else
                 {
                     callback(new BackendResult <Doc, ResultCode>(ResultCode.UnknownError));
                 }
             }), fileName1, progressCallback1, c);
         }
         else
         {
             callback(new BackendResult <Doc, ResultCode>(uploadUrlResponse.ResultCode));
         }
     }));
 }