microsoftgraph / microsoftgraph/msgraph-sdk-java

File Corruption in SharePoint Upload via Microsoft Graph API

Abierto
#2,339 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

status:waiting-for-triage type:bug
Lenguaje dominante
Java
Estrellas
444
Forks
154
Merge medio
18 h 28 min
PR fusionados (30 d)
4

Descripción

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_

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la rama simple-upload en el fragmento uploadFile proporcionado y revisa cómo consume document.contentToStream la llamada del Microsoft Graph SDK 5.80.0. Reproduce el caso intermitente mientras comparas el tamaño de origen, el tamaño en SharePoint tras la carga y el momento del webhook; se considera terminado cuando se haya identificado una causa fiable y una corrección verificada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java, kotlin, spring-boot
Área
api, backend, cloud
Tipo de issue
Error
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.