I currently have a project where I am using a simple viewer embedded in an html page. Currently, I have a simple code working where I upload a file, translate it to an svf file, and then display it in the viewer. Now that I am done that step, I am responsible for linking the viewer to our company's machine viewer website. Everything works the same excepts for the uploading of files. Before, when I uploaded a file I used a simple input type = file in html and then extracted all the file info. Once i did that, I used that in a PUT method using ajax jquery to upload the file to the forge cloud. I stored it under that "data": field. This is an example of what was included:
lastModified: 1591731544778
lastModifiedDate: Tue Jun 09 2020 15:39:04 GMT-0400 (Eastern Daylight Time) {}
name: "_MC-13793 CAM PKG INTEGRATED.iam (1).dwf"
size: 16561374
type: "model/vnd.dwf"
webkitRelativePath:
That worked fine and I was successfully able to upload the file and view it on the viewer. Now however, I cannot upload the file because we want our website to do that automatically without user input. Currently, our site is able to grab the name and path of the file that is to be uploaded and translated. I have used that name of the file in the PUT request but cannot use it for the "data": field in that request. I am wondering how I can grab all of that file info with just the fileName and path that I have. Or how I could change my code to included the data if I just have the filename available to me. Here is my uploadFile() method with the PUT request:
function uploadFile(){
$.ajax({
method: 'PUT',
url:"https://developer.api.autodesk.com/oss/v2/buckets/"+encodeURIComponent(bucketKey)+"/objects/"+encodeURIComponent(fileName)+"",
data: xfile,
contentType: false,
processData: false,
headers:{
Authorization: "Bearer " + access_token,
// "Cookie": "PF=JBSiy8wIC9cx9cWBlyuekG"
},
xhrFields: {
withCredentials: true
},
success:function(response){
console.log(response);
urn1 = response.objectId;
console.log(urn1);
urn2 = btoa(urn1);
console.log(urn2);
translateToSVF();
},
error:function(error){
console.log(error);
}
})
}
If i simply change the "data" field to just include the filename, the entire file doesn't get uploaded, how can I change this to include the entire file? This would allow the uploading of the file to be done automatically, without the user having to upload the file himself. Thanks for all the help! Cheers!
EDIT**
I just wanted to add that all of my dwf files which are to be uploaded are contained in the project folder, where the code is running.