I have a toucscreen tft connected to an ESP8266 the aim for which is to take a screeenshot (.bmp format) and upload to Google Drive. I have been following this tutorial.

Where I am stuck in how to proceed is the actual upload part. I have used the code in the tutorial up to line 264, and it is thereafter I don't know how to solve for. This reference project uses a function in a special library for the camera to parse it into packets and use client.write() to upload the packets. Relevant code here:

int i;
int packet_num = cameraPacketNum();
char packet[PIC_PKT_LEN] = {0};

for(i = 0; i < packet_num; i++)
    long packet_len = cameraGetPacket(i, packet);
    client.write((const uint8_t *)&packet[4], packet_len - 6);
    total += packet_len - 6;

cameraGetPacket(i, packet);

I looked at the code for the function but can't figure out what it's doing and how to replicate it. This is it here:

long cameraGetPacket(unsigned int i, char* buf) {
    char cmd[] = { 0xaa, 0x0e | camera_address, 0x00, 0x00, 0x00, 0x00 };


    if(i < camera_packet_num) {
        cmd[4] = i & 0xff;
        cmd[5] = (i >> 8) & 0xff;

        cameraSendCmd(cmd, 6);

        int pkt_len;

        if(i < (camera_packet_num - 1))
            pkt_len = PIC_PKT_LEN ;
            pkt_len = camera_last_packet_len;

        uint16_t cnt = Serial.readBytes((char *)buf, pkt_len);

        return cnt;
    } else {
        cmd[4] = 0xf0;
        cmd[5] = 0xf0;
        cameraSendCmd(cmd, 6);

    return "";

The Google Drive API reference states: "Add the chunk's data to the request body. Create chunks in multiples of 256 KB (256 x 1024 bytes) in size, except for the final chunk that completes the upload. Keep the chunk size as large as possible so that the upload is efficient."

How can I take an image saved to the SD on the tft and cut it into the appropriate sized chunks and use client.write() to upload it to Google Drive? This example (which received no responses) seems to have divided the image file into 1,000's to upload but I don't know if that is correct or efficient.

int Index;
for (Index = 0; Index < imageFile.length(); Index = Index+1000) {
  client.print(imageFile.substring(Index, Index+1000));

Another thing I am unsure about is whether I need to have the image file itself converted into Base64 or URLencoded. I have seen examples for the ESP32 CAM which do that, but I wonder if that is just the way that camera encodes images which then need to converted. The first example cited above doesn't have conversion code as it isn't an ESP32 CAM, but maybe it's happening in the background. The Google API doesn't make mention of it.

Any help would be greatly appreciated. Or any examples you can point me to that do this would be helpful too.

  • my StreamLib has ChunkedPrint. the library is in Library Manager. see the example
    – Juraj
    Jan 27 at 5:23
  • Thanks for pointing me to that. how might I might I adapt that for an image file? I've seen a few examples of chunking and uploading text, but an image file is something altogether different.
    – tstdenis
    Jan 27 at 18:56
  • It's really not. It's a file.
    – romkey
    Jan 29 at 5:23
  • what would be more helpful is offering how i can implement base64 with an image file since the examples only show a text string.
    – tstdenis
    Jan 29 at 22:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.