public async Task Add(Storage.StorageResponse storage) { Version.VersionRequest newVersion = new DataManagement.Data.Version.VersionRequest(Owner.Json.attributes.displayName, storage.id, Owner.Json.id); Dictionary<string, string> headers = new Dictionary<string, string>(); headers.AddHeader(PredefinedHeadersExtension.PredefinedHeaders.ContentTypeJson); headers.AddHeader(PredefinedHeadersExtension.PredefinedHeaders.AcceptJson); IRestResponse response = await CallApi(string.Format("/data/v1/projects/{0}/versions", Owner.Owner.Owner.ID), Method.POST, headers, null, newVersion, null); //Json = JsonConvert.DeserializeObject<Version.>(response.Content).data; }
internal Item(string fileName, Storage.StorageResponse storage, int version, Folder parentFolder) : base(parentFolder.Authorization) { Owner = parentFolder; Item.ItemRequest newItem = new DataManagement.Data.Item.ItemRequest(fileName, storage.id, 1, parentFolder); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.AddHeader(PredefinedHeadersExtension.PredefinedHeaders.ContentTypeJson); headers.AddHeader(PredefinedHeadersExtension.PredefinedHeaders.AcceptJson); IRestResponse response = CallApi(string.Format("data/v1/projects/{0}/items", parentFolder.Owner.ID), Method.POST, headers, null, newItem, null).Result; Json = JsonConvert.DeserializeObject <Item.ItemResponse>(response.Content).data; Owner.Contents.Items.Invalidate(); // need to force this list to rebuild }
//public override string ID { get { return Json.id; } } //public override string Name { get { return Json.attributes.name; } } /// <summary> /// Upload a files to the folder /// </summary> /// <param name="filePath">Full path of the file</param> /// <param name="createNewVersion">If file already on the folder, TRUE will create new version, FALSE will do nothing</param> /// <returns>The newly created item</returns> public async Task <Item> UploadFile(string filePath, bool createNewVersion) { // ToDo: check if file exists (then create new version) // Following this tutorial: // https://developer.autodesk.com/en/docs/data/v2/tutorials/upload-file/ // Step 1: Find the hub that has your resource // no need to navigate throuhg Hubs for this implementattion // Step 2: Find the project that has your resource // .Owner property //Step 3: Create a storage location string fileName = Path.GetFileName(filePath); Storage.StorageResponse storageDef = await CreateStorage(fileName); // Step 4: Upload a file to the storage location OSS.Bucket bucket = new OSS.Bucket(Authorization); string bucketKey, objectName; OSS.Bucket.Extract(storageDef.id, out bucketKey, out objectName); await bucket.UploadFile(filePath, bucketKey, objectName); var id = storageDef.id; Item item = this.Contents.Items.Contains(fileName); if (item == null) { // Step 5: Create the first version of the uploaded file item = new Item(fileName, storageDef, 1, this); } else { // Step 6: Update the version of a file await item.Versions.Add(storageDef); } return(item); }