How to upload file to server using PHP and CCHttpClient?

Hello.

I want to upload a file with POST method using CCHttpClient.

server has been all ready to receive the file because I use Java and Objective C already a successful upload.

I’m wondering how to make the POST data to the file in cocos2d -x.

    std :: string path = CCFileUtils :: sharedFileUtils () -> getWritablePath () + "temp.png";
    unsigned long buff = 0; 
    unsigned char * pBuffer = CCFileUtils :: sharedFileUtils () -> getFileData (path.c_str (), "r", & buff); 

First made ​​in the form of unsigned char data file,

    const char * fileBinary = (const char *) pBuffer; 

has a cast to const char format.

The following have made it to the POST data.

    std :: string boundary = "--------------------------- 14737809831466499882746641449";
    std :: string str = "\ r \ n--" + boundary + "\ r \ n"; 
    str = str + "Content-Disposition: attachment; name = \" upload_file \ "; filename = \" 11.png \ "\ r \ n"; 
    str = str + "Content-Type: application / octet-stream \ r \ n \ r \ n"; 
    str = str + fileBinary; <- This is the data portion of the file. 
    str = str + "\ r \ n--" + boundary + "- \ r \ n"; 

Do this by making a transfer to the POST method, the file is uploaded but uploaded file data has Just a 8 byte.

How do I create a data to send file?

Here is full code.

    std::string path = CCFileUtils::sharedFileUtils()->getWritablePath() + "temp.png";
    unsigned long buff = 0;
    unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(path.c_str(), "r", &buff);
    
    const char* fileBinary = (const char*)pBuffer;
    
    
    std::string boundary = "---------------------------14737809831466499882746641449";
    std::string bound = boundary;
    std::vector<std::string> headers;
    headers.push_back("Content-Type: multipart/form-data; boundary="+bound);
    
    std::string str = "\r\n--" + boundary + "\r\n";
    str = str + "Content-Disposition: attachment; name=\"upload_file\"; filename=\"11.png\"\r\n";
    str = str + "Content-Type: application/octet-stream\r\n\r\n";
    str = str + fileBinary;
    str = str + "\r\n--" + boundary + "--\r\n";

    
    CCHttpRequest* request = new CCHttpRequest();
    request->setUrl("SERVER ADDRESS"); 
    request->setHeaders(headers);
    request->setRequestType(CCHttpRequest::kHttpPost);
    request->setRequestData(str.c_str(), strlen(str.c_str()));
    request->setResponseCallback(this, httpresponse_selector(MainScene::complete));
    request->setTag("UP IMAGE");
    CCHttpClient::getInstance()->send(request);
    request->release();

I’m facing with this problem. Did you resolve it?