static bool FlushCachedFile (DropboxHandler *dropbox_handler_p) { bool success_flag = true; /* If there are any changes, upload them */ if (dropbox_handler_p -> dh_updated_flag) { int res; rewind (dropbox_handler_p -> dh_local_copy_f); res = drbPutFile (dropbox_handler_p -> dh_client_p, NULL, DRBOPT_PATH, dropbox_handler_p -> dh_dropbox_filename_s, DRBOPT_IO_DATA, dropbox_handler_p -> dh_local_copy_f, DRBOPT_IO_FUNC, fread, DRBOPT_END); success_flag = (res == DRBERR_OK); } return success_flag; }
gpointer upload_file (gpointer data) { int err; void* output; // Application key and secret. To get them, create an app here: // https://www.dropbox.com/developers/apps char *c_key = "lmg4kv8jw45nlsr"; //< consumer key char *c_secret = "xmq9x391l0y8nwy"; //< consumer secret char filename[200]; CustomData *cdata=(CustomData*)data; strcpy(filename,cdata->sink_filename); // User key and secret. Leave them NULL or set them with your AccessToken. // char *t_key = NULL; //< access token key // char *t_secret = NULL; //< access token secret char *t_key = "5j55oq1lf8h1zi2w"; //< access token key char *t_secret = "nvv5ps3hy4v4wy3"; //< access token secret // Global initialisation drbInit(); // Create a Dropbox client drbClient* cli = drbCreateClient(c_key, c_secret, t_key, t_secret); // Request a AccessToken if undefined (NULL) if(!t_key || !t_secret) { drbOAuthToken* reqTok = drbObtainRequestToken(cli); if (reqTok) { char* url = drbBuildAuthorizeUrl(reqTok); printf("Please visit %s\nThen press Enter...\n", url); free(url); fgetc(stdin); drbOAuthToken* accTok = drbObtainAccessToken(cli); if (accTok) { // This key and secret can replace the NULL value in t_key and // t_secret for the next time. printf("key: %s\nsecret: %s\n", accTok->key, accTok->secret); } else{ fprintf(stderr, "Failed to obtain an AccessToken...\n"); return NULL; } } else { fprintf(stderr, "Failed to obtain a RequestToken...\n"); return NULL; } } // Set default arguments to not repeat them on each API call drbSetDefault(cli, DRBOPT_ROOT, DRBVAL_ROOT_AUTO, DRBOPT_END); // upload current file FILE *file = fopen(filename, "r"); char fn[200]; memset(fn,0,sizeof(fn)); strcpy(fn,"/"); strcat(fn,filename); output = NULL; err = drbPutFile(cli, &output, DRBOPT_PATH, fn, DRBOPT_IO_DATA, file, DRBOPT_IO_FUNC, fread, DRBOPT_END); printf("File upload: %s\n", err ? "Failed" : "Successful"); fclose(file); output = NULL; //share public link to file drbShare(cli, &output, DRBOPT_PATH, fn, DRBOPT_END); drbLink* url = (drbLink*)output; // strcpy(link,url->url); We should return here!!!! drbDestroyClient(cli); // Global Cleanup drbCleanup(); gst_bus_post(cdata->bus,gst_message_new_application( GST_OBJECT_CAST(cdata->pipeline), gst_structure_new_empty("UploadDone"))); return url->url; }