'Uploaded Image to Sharepoint using Graph API contains no Content (.NET)

I alreadey use the following method to upload files (docx, xlsx) to our sharepoint. Now i'm trying to upload images (png, jpg) to the same library. I don't get any errors while uploading the image as a Stream. There is also no preview available for this image and i can't download it. The created sharepoint file looks like this: uploaded sharepoint image

I've also tried to use a list of HeaderOptions and set the content-type to "image/png".

My stream contains the stream and the imageformat. I am able to convert my stream back to an image and save it to my file system. So i think its not up to my stream and stream content. Since my function is works properly with docx files i also think its not up to any permission or connection topics...

This is my upload function:

    Public Async Function createImageUploadAsync(Stream As Stream, DriveItemID As String, Rootpath As String, filename As String) As Task(Of String)
    Dim FileId As String = ""
    Try

        'Dim Option As List(Of HeaderOption) = New List(Of HeaderOption) From {
        '    New HeaderOption("Content-Type", "image/png")
        '    }
        Dim ms As MemoryStream = New MemoryStream

        If _GraphClient IsNot Nothing Then
            Dim uploadedfile = Await _GraphClient.Sites(__DAL.SiteID).Lists(DriveItemID).Drive.Root.ItemWithPath(Rootpath + filename).Content.Request().PutAsync(Of DriveItem)(Stream)

            FileId = uploadedfile.id
        End If
    Catch ex As Exception
        If __DAL.Testbetrieb Then Stop
        __Prot.Err(ex, True)
    End Try
    Return FileId

End Function

Do you have any suggestions why my uploaded image is empty?



Solution 1:[1]

In case anyone else is facing the same problem...

After hours of research and tests, I found the solution for my problem:

You can upload PDF, Word and Excel files as a MemoryStream, as i have explained above. BUT you CAN'T upload images as a MemoryStream. You have to read the image as a FileStream and then you can upload it the same way.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Querentin