/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageFilePlatform"/> class. /// </summary> /// <param name="service">Instance of OneDriveService</param> /// <param name="oneDriveStorageFile">Instance of OneDriveStorageFile</param> public OneDriveStorageFilePlatform( OneDriveService service, OneDriveStorageFile oneDriveStorageFile) { _service = service; _oneDriveStorageFile = oneDriveStorageFile; }
public static async Task <string> GetThumbnail(OneDriveStorageFile file) { var thumb = await file.GetThumbnailSetAsync(); if (thumb == null) { return(null); } return(thumb.Source ?? thumb.Large ?? thumb.Medium ?? thumb.Small); }
public static async Task <string> GetDownloadURL(this OneDriveStorageFile oneDriveFile) { var requestMessage = OneDriveService.Instance.Provider.Drive.Items[oneDriveFile.OneDriveItem.Id].Content.Request().GetHttpRequestMessage(); await OneDriveService.Instance.Provider.AuthenticationProvider.AuthenticateRequestAsync(requestMessage).AsAsyncAction().AsTask(); string headerStr = "\r\n"; foreach (var header in requestMessage.Headers) { headerStr += header.Key + ": " + header.Value.First() + "\r\n"; } return(requestMessage.RequestUri.AbsoluteUri.Replace("https", "http") + headerStr); }
/// <summary> /// 上传图片至OneDrive /// </summary> /// <param name="image">图片文件</param> /// <returns></returns> public async Task <OneDriveImage> UploadImage(StorageFile image, OneDriveImageGroup group) { if (_appFolder == null) { throw new UnauthorizedAccessException("You need to complete OneDrive authorization before you can upload the image"); } var imageFolder = await GetImgSaveFolder(); var per = await image.GetBasicPropertiesAsync(); string fileId = ""; string name = ""; string extension = Path.GetExtension(image.Path); bool isAutoRename = Convert.ToBoolean(AppTools.GetLocalSetting(AppSettings.AutoRename, "True")); string fileName = isAutoRename ? Guid.NewGuid() + extension : image.Name.Trim(); OneDriveStorageFile cre = null; try { // 这里要对文件大小进行判断,以4MB为分水岭,需要用不同的办法上传 if (per.Size < 4 * 1024 * 1024) { using (var stream = await image.OpenReadAsync()) { cre = await imageFolder.StorageFolderPlatformService.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting, stream); fileId = cre.OneDriveItem.Id; name = cre.OneDriveItem.Name; } } else { using (var stream = await image.OpenReadAsync()) { cre = await imageFolder.StorageFolderPlatformService.UploadFileAsync(fileName, stream, CreationCollisionOption.ReplaceExisting, 320 * 1024); fileId = cre.OneDriveItem.Id; name = cre.OneDriveItem.Name; } } string link = LinkConvert(fileId); var item = new OneDriveImage(name, await AppTools.ConvertFileToImage(image), group, link, fileId); return(item); } catch (Exception) { return(null); } }