microsoftgraph / microsoftgraph/msgraph-sdk-java

File Corruption in SharePoint Upload via Microsoft Graph API

Aperta
#2,339 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

status:waiting-for-triage type:bug
Lingua principale
Java
Stelle
444
Fork
154
Merge medio
18h 28m
PR unite (30g)
4

Descrizione

Describe the bug

I am using the Microsoft Graph API 5.80.0 to upload files to SharePoint from a Java Spring Boot application. The upload works fine in normal conditions, but some files become corrupted while uploading & so unable to download from SharePoint.

Most of the upload files are smaller than 4 MB, so I am using the simple upload method (PUT request).
The upload process completes successfully (returns 200 OK with a valid file ID). When I receive the webhook for the same the file size is 0 & not able to open the file as the file is corrupted. It happens randomly for a few of the requests.

private fun uploadFile(document: DocumentUploadStream) {
    val timeMillis = System.currentTimeMillis()
    val buildDriveItemRequest : DriveItemRequestBuilder = microsoftGraphClient.drives("driveId").root().itemWithPath(document.path)

    
    if (document.size < 4 * 1024 * 1024) { 
        // Simple upload for small files
        val driveItem = retry {
            refreshToken { 
                buildDriveItemRequest.content().buildRequest()
                    .put(document.contentToStream.readAllBytes()) 
            }
        }
        logger.info { "Upload done ${document.path}, id: ${driveItem?.id}, time: ${(System.currentTimeMillis() - timeMillis)/1000}s" }
        document.id = driveItem?.id
    } else { 
        // Large files use upload sessions (this part is working fine)
    }
}

data class DocumentUploadStream(
        val path: DocumentPath,
        val contentToStream: InputStream,
        val size: Long
)
Expected behavior

The file should not get corrupted on upload.
Any insights or recommendations would be greatly appreciated!
Thanks

How to reproduce

With the attached snippet of code, it should be reproducible randomly.

SDK Version

5.80.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_

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal ramo simple-upload nello snippet uploadFile fornito e verifica come document.contentToStream viene consumato dalla chiamata al Microsoft Graph SDK 5.80.0. Riproduci il caso intermittente confrontando la dimensione dell’origine, la dimensione caricata in SharePoint e la tempistica del webhook; il lavoro è completato quando sono state identificate una causa affidabile e una correzione verificata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, kotlin, spring-boot
Ambito
api, backend, cloud
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.