how to download images to device resources folder

i need to download images from the server to device.
i tried using CCHttpRequest

void fileDownloading::onHttpRequestCompleted(cocos2d::CCNode *sender, void *data)
{
    cocos2d::extension::CCHttpResponse *response = (cocos2d::extension::CCHttpResponse*)data;

    if (!response)
    {
        return;
    }

    // You can get original request type from: response->request->reqType
    if (0 != strlen(response->getHttpRequest()->getTag())) 
    {
        cocos2d::CCLog("%s completed", response->getHttpRequest()->getTag());
    }

    int statusCode = response->getResponseCode();
    char statusString[64] = {};
    sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag());
   // m_labelStatusCode->setString(statusString);
    cocos2d::CCLog("response code: %d", statusCode);

    if (!response->isSucceed()) 
    {
        cocos2d::CCLog("response failed");
        cocos2d::CCLog("error buffer: %s", response->getErrorBuffer());
        return;
    }


    // dump data
    std::vector *buffer = response->getResponseData();
    printf("Http Test, dump data: ");
    CCImage * img=new CCImage();
    img->initWithImageData(&(buffer->front()), buffer->size());

    cocos2d::CCTexture2D* texture= new cocos2d::CCTexture2D();
texture->initWithImage(img); //in this line I am getting exception
//
CCSprite* sprite = CCSprite::createWithTexture(texture);
this->addChild(sprite, 10);
sprite->setPosition(ccp(200,200));

   /*for (unsigned int i = 0; i < buffer->size(); i++)
    {
        printf("%c", (*buffer)[i]);
    }*/
    printf("\n");
}

by using above code i am able to display image,but i need to store the image in device memory card
how can i do that one.
can any one help me to download images to device.

I face the same problem.
I can download images on Windows hard drive with VC++2010 and put it on D:.
But how can I put the image on Android SDCard?

try this code

std::vector * buffer = response->getResponseData();
FILE * fp = fopen("raw://sdcard/images/image.png", "wb");
if (fp)
{
fwrite(&(buffer->front()), 1, buffer->size(), fp);
fclose(fp);
}

I tried like this:
FILE *p=fopen(“raw://sdcard/1000.png”,“wb”);
but the returned p is NULL.
Whether the path is wrong or just can not create a new file or something else?

I figured it out.
a added two permission in the project AndroidManifest.xml file.


Now I can create file on the sdcard.
But a new problem occurs,the size of file is 0kb,it’s so weared.

A ha

Now evrything is fine!

A small not on the path: you should NOT hardcode the path on android.
You do not know it the SDCard is still mounted at /sdcard on future versins of Android. (and you do not know if there is an SD card mounted at all)

You may take a look at CCFileUtils if it provides a method to access externaö storage, otherwise you should call through JNI.

Further reading:
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

This will also give some clues on where to put the data (for example if you want to place the image into the gallery)

But I’m developing the platform-independent project on Windows with vs2010 using C++.
Thus how can I use CCFileUtils to judge whether the device has a sdcard or not?

hi,
can any one help me to get resource folder path in iphone.

actually i am downloading images from server

in android i am able download data to
1)SD card (“/mnt/sdcard/”);
2) data to writable path (CCFileUtils::sharedFileUtils()->getWriteablePath());
3) data to project resource folder (by directly giving image name with out any path “image.png” );

NOTE: here from the above: if i use 1st and 2nd option to download data then user will get access to that data and user can delete it,so we have to check every time whether data is present or not and it is little bit complicated thing
if we use 3rd option we are not giving any access to user and we no need to check every time whether data is there or not.

in iphone i am downloading data to

  1. data to writable path (CCFileUtils::sharedFileUtils()->getWriteablePath());
    here i am trying to download data to resource folder
    here my question is how can we download data to iphone resource folder path.

can i download data to resource folder in iphone?