Skip to content

Download Callback interface issue #1191

@Chrys4lisfag

Description

@Chrys4lisfag

I am trying to async callback download image to memory and Download interface is not user-friendly for me.

so we have write callback for DownloadAsync method but we don't have DownloadCallback method where I could have response ctx or some sort where I could just do:

const auto buffer = std::make_shared<std::vector<uint8_t>>();
auto f = session->DownloadAsync( cpr::WriteCallback{
[buffer]( std::string_view data, intptr_t /*userdata*/, auto ctx ) -> bool
{
	buffer->insert( buffer->end(), data.begin(), data.end() );

	if ( ctx->finished && ctx->status_code == 200 )
	{
			//somelogic	
	}

	return true;
} } );

or just DownloadCallback that accepts cpr::Response& and called when download finished where body has payload bytes

Currently, I don't know how conveniently do such thing.
session->GetDownloadFileLength() - it does request inside, so the logic is not async anymore
SetProgressCallback - sure we can use it but why do we need two callbacks to simply downloading file?

So am I missing something here to conveniently download the file in a callback way?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions