public string SaveAttachment(Attachment attachment) { try { DropNetClient _client = new DropNetClient(AppConstants.DropboxClientId, AppConstants.DropboxClientSecret); _client.UserLogin = Storage.Dropbox.Token; DropNet.Models.UserLogin login = _client.GetAccessToken(); _client.UploadFile("/", attachment.AttachmentName, attachment.AttachmentBytes); return "Uploaded Sucessfully."; } catch (Exception s) { return s.Message; } //return ""; }
private string SaveAttachment(Attachment attachment) { string oneDriveResourceId = AppConstants.oneDriveResourceId; string oneDriveApiEndpoint = AppConstants.oneDriveApiEndpoint; string accessToken = OAuthController.GetAccessTokenFromRefreshToken(oneDriveResourceId); // Prepare the HTTP request using the new "File" APIs HttpWebRequest webRequest = WebRequest.CreateHttp(oneDriveApiEndpoint + "/files/Add(name='" + attachment.AttachmentName + "', overwrite=true)"); webRequest.Accept = "application/json;odata=verbose"; webRequest.Headers.Add("Authorization", string.Format("Bearer {0}", accessToken)); webRequest.Method = "POST"; webRequest.ContentLength = attachment.AttachmentBytes.Length; webRequest.ContentType = "application/octet-stream"; Stream requestStream = webRequest.GetRequestStream(); requestStream.Write(attachment.AttachmentBytes, 0, attachment.AttachmentBytes.Length); requestStream.Close(); // Make the request to SharePoint and get the response. HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); // If the response is okay, read it if (webResponse.StatusCode == HttpStatusCode.OK) { Stream responseStream = webResponse.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); return reader.ReadToEnd(); } return "StatusCode was not OK!"; }
public string SaveToOneDrive(Attachment attachment) { try { return SaveAttachment(attachment); } catch (Exception e) { return "There was an exception: " + e.Message + "\n\n" + e.StackTrace; } }
public string SaveAttachment(AttachmentsDemoWeb.Constants.Attachment attachment) { try { DriveRestClient restClient = new DriveRestClient(AppConstants.GoogleDriveClientId, AppConstants.DropboxClientSecret, googledriveRedirectUrl.ToString()); restClient.Token = Storage.GoogleDrive.Token; string uploadText = restClient.UploadFile(attachment.AttachmentName, attachment.AttachmentBytes); return("Uploaded Sucessfully."); } catch (Exception s) { return(s.Message); } //return ""; }