microsoftgraph / microsoftgraph/msgraph-sdk-java

When uploading file using LargeFileUploadTask (streaming and not in one part) the file getting corrupted in the SharePoint server

Ouverte
#2,257 22 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Status: Needs Investigation type:bug
Langage dominant
Java
Étoiles
444
Forks
154
Merge moyen
18 h 28 min
PR mergées (30 j)
4

Description

Describe the bug

I am using latest version of graph api - 6.24.0
When I uploading any file using
graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId(getDriveItemIdFromRootPath(filePath)).content().put(fileContent) file is uploading correct.

When I upload via the LargeUploadTask - file is corrupted for any file such as MSOffice file or dat file or jar file.
For MSOffice the file can't be opened and for the dat file null values are being inserted to the file.
The code that I am using for the uploading in streaming is:
LargeFileUploadTask largeFileUploadTask = null;
IProgressCallback callback = null;
UploadResult uploadResult = null;
try {
int spoPartSize = 5242880;

        // Set body of the upload session request
        // This is used to populate the request to create an upload session
        DriveItemUploadableProperties driveItemUploadableProperties = new DriveItemUploadableProperties();
        driveItemUploadableProperties.getAdditionalData().put("@microsoft.graph.conflictBehavior", "replace");

        // Finish setting up the request body
        CreateUploadSessionPostRequestBody uploadSessionPostRequestBody = new CreateUploadSessionPostRequestBody();
        uploadSessionPostRequestBody.setItem(driveItemUploadableProperties);

        // Create the upload session
        UploadSession uploadSession = graphServiceClient.drives()
                .byDriveId(driveId)
                .items()
                .byDriveItemId(getDriveItemIdFromRootPath(filePath))
                .createUploadSession().post(uploadSessionPostRequestBody);

        if (null == uploadSession) {
            throw new SPOException("SPOWrapper::uploadObjectInParallel: Could not create upload session");
        }

        // Create the large file upload task
        largeFileUploadTask = new LargeFileUploadTask(graphServiceClient.getRequestAdapter(),
                uploadSession,
                fileContent,
                fileSize,
                spoPartSize,
                DriveItem::createFromDiscriminatorValue);

        if (null == largeFileUploadTask) {
            throw new SPOException("SPOWrapper::uploadObjectInParallel: Could not create upload task");
        }

        // Create a callback used by the upload provider
        callback = new SPOProgressCallback(spoFileCopy);

        // Do the upload
        uploadResult = largeFileUploadTask.upload(spoRequestMaxAttempts, callback);
        if (uploadResult == null || !uploadResult.isUploadSuccessful()) {
            throw new SPOException(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' wasn't uploaded successfully via upload method", originalFilePath));
        } else {
            logger.debug(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' uploaded successfully via upload method", originalFilePath));
        }
    } catch (Exception e) {
        boolean spoIgnoreFailureWhenUploadingFileInParts = Boolean.valueOf(hostProperties.getParameterValueFromAdditionalParamsOrFromAftConfig(mftPropertiesConfig, PropertyData.spoIgnoreFailureWhenUploadingFileInParts, AdditionalParametersConsts.spoIgnoreFailureWhenUploadingFileInParts));
        logger.error(String.format("Error in SPOWrapper::uploadObjectInParallel, filePath = '%s', fileSize = '%s' : %s", originalFilePath, fileSize, e.getMessage()), e);
       /* try {
            if (uploadTask != null && callback != null) {
                uploadResult = uploadTask.resume(spoRequestMaxAttempts, callback);
                if (uploadResult == null || !uploadResult.isUploadSuccessful()) {
                    throw new SPOException(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' wasn't uploaded successfully via resume method", originalFilePath));
                } else {
                    logger.debug(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' uploaded successfully via resume method", originalFilePath));
                    return;
                }
            }
        } catch (Exception ex) {
                  logger.error(String.format("Error in SPOWrapper::uploadObjectInParallel, filePath = '%s', fileSize = '%s' : %s", originalFilePath, fileSize, e.getMessage()), e);
        throw e;
    } finally {
        logger.debug(String.format("End SPOWrapper::uploadObjectInParallel: filePath= '%s', fileSize= %s", originalFilePath, fileSize));
    }

Thanks,
Itay

Expected behavior

File should uploaded corrdct with same bytes and noit being corrupted.

How to reproduce

Uploading file using LargeFileUploadTask

SDK Version

6.24/0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le chemin d’upload de LargeFileUploadTask utilisé avec le streaming de fileContent et comparez-le au chemin fonctionnel content().put(fileContent). Reproduisez le problème avec un fichier binaire de plus d’une partie, puis examinez les données de la requête multipart et la gestion de la session d’upload. Le travail est terminé lorsque le fichier uploadé contient les mêmes octets que le fichier source pour les fichiers Office, DAT et JAR.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
api
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.