Has anyone been able to successfully upload a .pdf file to a row using VBA?

tommyrossman
tommyrossman ✭✭✭
edited 02/10/25 in API & Developers

Hello, I've been able to load a .pdf file to a specific row on my sheet. However, the file isn't converted correctly when using MS Access 16 VBA on Windows. I've tried using bytearray, ADODB.stream, Base64 encoded, and multiple other variations that AI has recommended, but I'm not able to read the uploaded file using any of them. I've manually uploaded the file, and it has no issues. So, I know the original file is not corrupt, and it is something with reading the file and passing it that it's not able to read the uploaded pdf. Has anyone been able to do a successful upload and read using API 2.0?

Answers

  • Isaac A.
    Isaac A. Employee

    Hi @tommyrossman!

    I haven’t personally created a similar solution, but I can provide you with our API documentation covering Attachments for reference:
    Smartsheet API - Attachments.

    I couldn't find other recent similar posts, so if you don’t receive a response from the Community, consider checking out Stack Overflow to connect with other developers for more help.

    I hope this helps!

    Cheers,
    Isaac.

    Need more information? 👀 |Help and Learning Center
    こんにちは (Konnichiwa), Hallo, Hola, Bonjour, Olá, Ciao! 👋 |Global Discussions

  • Thanks @Isaac A. I'm at a loss. I've read that many times, and I can get the file to attach to the row, but it's not able to be read/opened. I've tried a very basic file, even one that has no text. I suspect there be something wrong with the file length or the format of the file that I am sending when converting in VBA. Unfortunately, I'm not finding anything related to file uploads and VBA in Stack Overflow, but I'll try to chat up some developers over there. Thanks again.

  • I haven't attached a file to a row using VBA, but I'm curious about your attempts to use a byte array. I've uploaded files to other sites with HTTP PUT after reading them into a byte array (in VBA) with the code below.

    Are you "redimming" your array with the file length after subtracting 1 from it to account for the array index being zero-based? Have the last byte element in the array being null or empty or something could cause problems when trying to open it. (I apologize if that sounds condescending. I do not intend it to. I just had the same problem when trying to read a file into a byte array.)

    Dim FileLength As Long

    FileLength = FileLen(FullPath) - 1


    Dim fileByteArray() As Byte

    ReDim fileByteArray(FileLength)


    Dim FileNumber As Integer

    FileNumber = FreeFile


    Open FullPath For Binary As #FileNumber

    Get #FileNumber, , fileByteArray

    Close #FileNumber