-
Notifications
You must be signed in to change notification settings - Fork 145
Closed
microsoftgraph/msgraph-sdk-java-core
#1548Labels
Description
Hi,
I use your example and it's failed
// Initialize the file input stream and get the file size
InputStream file = new FileInputStream("File-Path");
long fileSize = file.available();
// Set the DriveItemUploadableProperties
// This is used to populate the request to create an upload session
DriveItemUploadableProperties driveItemUploadableProperties = new DriveItemUploadableProperties();
driveItemUploadableProperties.setName("fileName");
driveItemUploadableProperties.setFileSize(fileSize);
Map<String, Object> additionalData = new HashMap<>();
additionalData.put("@microsoft.graph.conflictBehavior", "replace");
driveItemUploadableProperties.setAdditionalData(additionalData);
// Finish setting up the request body
CreateUploadSessionPostRequestBody uploadSessionPostRequestBody = new CreateUploadSessionPostRequestBody();
uploadSessionPostRequestBody.setItem(driveItemUploadableProperties);
// Create the upload session
String myDriveId = graphClient.me().drive().get().getId();
UploadSession uploadSession = graphClient.drives()
.byDriveId(myDriveId)
.items()
.byDriveItemId("root/fileName")
.createUploadSession().post(uploadSessionPostRequestBody);
// Create the large file upload task
LargeFileUploadTask<DriveItemUploadableProperties> uploadTask =
new LargeFileUploadTask(graphClient.getRequestAdapter(),
uploadSession,
file,
fileSize,
DriveItemUploadableProperties::createFromDiscriminatorValue);
try{
UploadResult<DriveItemUploadableProperties> uploadResult = uploadTask.upload();
} catch(ApiException | InterruptedException exception) {
System.out.println(exception.getMessage());
}I am failing when trying to create UploadSessin
I use in byDriveItemId also your example ("root/fileName" and it's not working
Thanks,
Itay