Re: Problem with writing image file.
Re: Problem with writing image file.
- Subject: Re: Problem with writing image file.
- From: Scott Anguish <email@hidden>
- Date: Mon, 2 Apr 2007 05:42:04 -0400
the code here is more CF than Cocoa.
are you trying to download the data synchronously? async?
Have a look at the URL Loading System documentation. it covers the
NSURL* interfaces.
On Apr 2, 2007, at 5:17 AM, Dan Rodricks wrote:
Hi All,
I want to write an image to disk. Below are the functions that i'm
using to
write the image.By using this, image is not fully writing on the
disk, some
byte is missing that is why image is not properly shown.
const char* url = "http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg
";
const char* fileUrl = "file//localhost/private/tmp/
1418878_1e92283336_m.jpg"
void Flickr::beginCFStreamDownload(const char* url, const char*
fileUrl)
{
CFHTTPMessageRef request;
CFReadStreamRef readStream;
CFDataRef data=NULL;
CFURLRef urlRef;
CFURLRef fileUrlRef;
urlRef = CFURLCreateWithBytes( kCFAllocatorDefault, (const UInt8*)url,
strlen( url ), kCFStringEncodingUTF8, NULL );
fileUrlRef = CFURLCreateWithBytes( kCFAllocatorDefault,
(constUInt8*)fileUrl, strlen( fileUrl ), kCFStringEncodingUTF8, NULL
);
request = CFHTTPMessageCreateRequest(kCFAllocatorDefault,
CFSTR("GET"),
urlRef, kCFHTTPVersion1_1);
// Set the body.
CFHTTPMessageSetBody(request, data);
if (request == nil)
{
}
else
{
readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault,
request);
CFRelease(request);
CFReadStreamSetProperty(readStream,
kCFStreamPropertyHTTPShouldAutoredirect,
kCFBooleanTrue);
CFWriteStreamRef writeStream = CFWriteStreamCreateWithFile(NULL,
fileUrlRef);
if (writeStream)
{
CFWriteStreamOpen(writeStream);
Write_file(readStream, writeStream);
CFRelease(writeStream);
}
}
}
void Flickr::Write_file(CFReadStreamRef stream, CFWriteStreamRef
writeStream)
{
// CFWriteStreamRef writeStream = (CFWriteStreamRef)[writeStreams
objectForKey:url];
CFReadStreamOpen(stream);
UInt8 buf[512];
CFIndex totalBytesRead = 0, bytesRead = 512;
CFIndex totalBytesWritten = 0;
do
{
bytesRead = CFReadStreamRead(stream, buf, 512);
totalBytesRead += bytesRead;
if (writeStream)
{
totalBytesWritten += CFWriteStreamWrite(writeStream, buf, bytesRead);
//CAlert::InformationAlert("ttttt");
}
} while (bytesRead == 512);
CFWriteStreamClose(writeStream);
CFReadStreamClose(stream);
}
Can anyone give me write way to solve this problem?
Thanks in Advance.
Dan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden