Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:14:35+00:00 2026-05-30T21:14:35+00:00

I’m developing a linux app programmed in C which processes gdk pixbuf images and

  • 0

I’m developing a linux app programmed in C which processes gdk pixbuf images and then should send them to a remote server via ftp (libcurl). The images are saved into a gchar buffer with gdk_pixbuf_save_to_buffer.

The problem is I don’t know how to use the data in this buffer in conjunction with libcurl read callback function to send the image properly to the remote server. All my attempts so far have produced random bytes into the resulting file.

There is an example of the libcurl read callback function which looks like this:

static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
    size_t retcode = fread(ptr, size, nmemb, stream);
    return retcode;
} 

I would need to do my own callback function that gets the gchar buffer as input instead of file stream and reads size*nmemb bytes from it and stores it to *ptr.

This is related to my previous question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:14:37+00:00Added an answer on May 30, 2026 at 9:14 pm

    The read_callback() is a function which CURL calls when it need to obtain data that will be uploaded to the server. Imagine that read_callback() is something similar to fread(). When called it performs any voodoo-mumbo-jumbo that is needed, but in the end uploadable data must be stored in *ptr buffer, which is curl’s internal buffer. For your in-memory buffer memcpy() will do just fine as body of read_callback(), so you don’t need real fread() at all.

    size * nmemb tells you how big buffer curl has reserved for a single chunk of data. The last void* is a pointer which was set by CURLOPT_READDATA option – it’s a do-what-ever-you-need-with-it kind of pointer, so it can point to a structure containing data which you’re uploading and a some additional info e.g. current progress.

    You may use this as a sample:

    #include <gdk-pixbuf/gdk-pixbuf.h>
    #include <stdlib.h>
    #include <curl/curl.h>
    #include <string.h>
    
    struct transfer
    {
        gchar *buf;
        gsize total;
        size_t uploaded;
    };
    
    static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *data)
    {
        struct transfer * tr = data;
        size_t left = tr->total - tr->uploaded;
        size_t max_chunk = size * nmemb;
        size_t retcode = left < max_chunk ? left : max_chunk;
    
        memcpy(ptr, tr->buf + tr->uploaded, retcode); // <-- voodoo-mumbo-jumbo :-)
    
        tr->uploaded += retcode;  // <-- save progress
        return retcode;
    } 
    
    int main()
    {
        GdkPixbuf * gbuffer = NULL;
        GError * error = NULL;
        gchar * buffer;
        gsize size;
        g_type_init();
        gbuffer = gdk_pixbuf_new_from_file("g.png", &error);
        gdk_pixbuf_save_to_buffer(gbuffer, &buffer, &size, "jpeg", &error, NULL);
    
        struct transfer tr = {buffer, size, 0};
    
        CURL *easyhandle = curl_easy_init();
        curl_easy_setopt(easyhandle, CURLOPT_READFUNCTION, read_callback); 
        curl_easy_setopt(easyhandle, CURLOPT_READDATA, &tr); // <-- this will be *data in read_callback()
        curl_easy_setopt(easyhandle, CURLOPT_UPLOAD, 1L); 
        curl_easy_setopt(easyhandle, CURLOPT_URL, "http://example.com/upload.php");
        CURLcode rc = curl_easy_perform(easyhandle);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.