Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Called by the µC/HTTP-client core when the form table is formatted to be sent.

Each HTTPc_MULTIPART_FILE objects contained in a table form must have set up a hook function pointer with the parameter OnFileTx. The HTTPc transmit buffer pointer and the length available inside are passed as argument to allow the hook function to copy the data file directly inside the HTTPc buffer.

Prototype

Code Block
CPU_BOOLEAN  HTTPc_FormMultipartFileHook (HTTPc_CONN_OBJ        *p_conn_obj,
                                          HTTPc_REQ_OBJ         *p_req_obj,
                                          HTTPc_MULTIPART_FILE  *p_file_obj,
                                          CPU_CHAR              *p_buf,
                                          CPU_INT16U             buf_len,
                                          CPU_INT16U            *p_len_wr);


Arguments

p_conn_obj

Pointer to the current HTTPc Connection Object.

p_req_obj

Pointer to the current HTTPc Request Object.

p_file_obj

Pointer to the Multipart File object.

p_buf

Pointer to transmit buffer.

buf_len

Length available inside the transmit buffer.

p_len_wr

Data length actually written inside the buffer by the hook function.

Return Values

DEF_YES, if all the data have been written to the buffer.

DEF_NO,   otherwise

Required Configuration

None.

Notes / Warnings

None.

Example Template

Code Block
languagecpp
titleListing - Multipart File Hook Function Example Code
linenumberstrue
static  CPU_BOOLEAN  HTTPc_FormMultipartFileHook (HTTPc_CONN_OBJ        *p_conn_obj,
                                                  HTTPc_REQ_OBJ         *p_req_obj,
                                                  HTTPc_MULTIPART_FILE  *p_file_obj,
                                                  CPU_CHAR              *p_buf,
                                                  CPU_INT16U             buf_len,
                                                  CPU_INT16U            *p_len_wr);
{
    FS_FILE      *p_file;
    FS_FLAGS      fs_flags;
    CPU_SIZE_T    file_rem;
    CPU_SIZE_T    size;
    CPU_SIZE_T    size_rd;
    CPU_BOOLEAN   is_open;
    CPU_BOOLEAN   finish;
    FS_ERR        err_fs;


    finish  = DEF_YES;
    is_open = FSFile_IsOpen("index.html",
                            &fs_flags,
                            &err_fs);
    if (err_fs != FS_ERR_NONE) {
        return (finish);
    }

    if (is_open == DEF_NO) {
        fs_flags = 0;
        DEF_BIT_SET(fs_flags, FS_FILE_ACCESS_MODE_RD);
        DEF_BIT_SET(fs_flags, FS_FILE_ACCESS_MODE_CREATE);
        p_file = FSFile_Open("index.html",
                              fs_flags,
                             &err_fs);
        if (err_fs != FS_ERR_NONE) {
            return (finish);
        }
        p_req->UserDataPtr = (void *)p_file;

    } else {
        p_file = (FS_FILE *)p_req->UserDataPtr;
    }

    file_rem = p_file->Size - p_file->Pos;
    if (file_rem <= 0) {
       *p_len_wr = 0;
        finish   = DEF_YES;
        FSFile_Close(p_file, &err_fs);
        goto exit;
    }

    size = DEF_MIN(file_rem, buf_len);

    size_rd = FSFile_Rd(p_file, p_buf, size, &err_fs);
    if (err_fs != FS_ERR_NONE) {
        return (finish);
    }

   *p_len_wr = size_rd;
    finish   = DEF_NO;

exit:
    return (finish);
}
Info

This code uses  the µC/FS File System for example purposes.