# withProgressCallback

**URL:** <https://forum.juce.com/t/withprogresscallback/63970>\
**Category:** Audio Plugins\
**Created:** [October 28, 2024, 3:43pm UTC](https://forum.juce.com/t/withprogresscallback/63970 "2024-10-28T15:43:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hilay](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hilay](https://forum.juce.com/u/Hilay)\
**Post date:** [October 28, 2024, 3:43pm UTC](https://forum.juce.com/t/withprogresscallback/63970/1 "2024-10-28T15:43:32Z")

</div>

Hey im trying to create a callback function that will update an `atomic<float>` that will will reference the percentage of the upload, but the callback is never being called:

```auto
url = url.withFileToUpload("file", userAudioFile, "audio/wav")
	.withParameter("token", token)
	.withParameter("bpm", String(globalVars.getBpm()))
	.withParameter("genre", globalVars.getGenere());
DBG("API URL: " + url.toString(true));

// Create input stream with progress tracking
auto progressCallback = [&globalVars](int bytesSent, int totalBytes) {
	DBG("Bytes sent: " + String(bytesSent) + " Total bytes: " + String(totalBytes)); 
//this is never printed
	if (totalBytes > 0)
	{
		float progress = static_cast<float>(bytesSent) / totalBytes;
		DBG("Raw progress: " + String(progress));
		globalVars.setUploadProgress(progress);
	}
	return true;
	};

URL::InputStreamOptions options(URL::ParameterHandling::inPostData);
options.withProgressCallback(progressCallback);

```

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [October 28, 2024, 4:19pm UTC](https://forum.juce.com/t/withprogresscallback/63970/2 "2024-10-28T16:19:43Z")

</div>

I think you are using a builder function wrong here. [URL:: InputStreamOptions::withProgressCallback](https://docs.juce.com/master/classURL_1_1InputStreamOptions.html#a16168c3167de47c6c61cb81796e647a2) returns a copy of the options with that option added. However from looking at the code it seems like you didn’t use the return value and probably used the original options and not the modified copy.

Rewrite your code like:

```auto
auto options = URL::InputStreamOptions (URL::ParameterHandling::inPostData)
    .withProgressCallback (progressCallback);

```

---

<div class="post-metadata">

**Author:** ![Hilay](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hilay](https://forum.juce.com/u/Hilay)\
**Post date:** [October 28, 2024, 4:21pm UTC](https://forum.juce.com/t/withprogresscallback/63970/3 "2024-10-28T16:21:18Z")

</div>

That worked! wow tnx
