visual c++ - Uploading image to flicker in c++ -


I am making an application to upload an image to Flickr using VCO + Win32, Wininet. I am able to get frob, tokens properly but when I try to upload the image, the post size is getting bigger.

The headers are created as follows:

  wstring wstrAddHeaders = L "content-type: multipart / form data; border = abcd \ r \ n"; WstrAddHeaders + = "Host: api.flickr.com \ r \ n"; Wchar_t tempStr [MAX_PATH]; Wsprintf (L "Content-Length:% ld \ r \ n", szTotalSize); WstrAddHeaders + = tmpStr; WstrAddHeaders + = L "\ r \ n"; Hunterter H. Session = Internet Connect (HE Internet, L "www.flickr.com", InterDEDFUBHAL_Http_PORT, Faucet, Faucet, Internal Services HTTP, 0, 0); If (hSession == NULL) {dwErr = GetLastError (); Return; }  

The content of the post request has been made as follows:

  wstring wstrboundry = l "- ABCD \ r \ n"; Wstring wstrContent = wstrBoundry; WstrContent + = "content-presentation: form-data; name = \" API_key \ "\ r \ n \ r \ n"; WstrContent + = wstrAPIKey.c_str (); WstrContent + = L "\ r \ n"; WstrContent + = wstrBoundry; WstrContent + = "Content-Presentation: Form-Data; Name = \" auth_token \ "\ r \ n \ r \ n"; WstrContent + = m_wstrToken.c_str (); WstrContent + = L "\ r \ n"; WstrContent + = wstrBoundry; WstrContent + = "content-presentation: form-data; name = \" API_sig \ "\ r \ n \ r \ n"; WstrContent + = wstrSig; WstrContent + = L "\ r \ n"; WstrContent + = wstrBoundry; WstrContent + = "content-presentation: form-data; name = \" photo \ "; filename = \" c: \\ test.jpg \ ""; WstrContent + = L "\ r \ n"; WstrContent + = L "Content-Type: Image / JPEG \ r \ n \ r \ n"; Wstring wstrFilePath (L "C: \\ test.jpg"); Cataluff File; HRESULT HR = S_OK; Hr = file.Create (wstrFilePath.c_str (), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); If (FAILED (HR)) {return; } Ulongong Nellan; Hr = file GetSize (nLen); If (nLen> (DWORD) -1) {return; } Char * fileBuf = New Four [NLN]; File.Read (fileBuf, nLen); Wstring wstrLastLine (L "\ r \ n - ABCD - \ r \ n"); Size_t szTotalSize = sizeof (wchar_t) * (wstrContent.length ()) + size (wchar_t) * (wstrLastLine.length ()) + nLen; Unsigned four * buffer = (unsigned char *) malloc (szTotalSize); Memset (buffer, 0, szTotalSize); Memcpy (buffer, wstrContent.c_str (), wstrContent.length () * sizeof (wchar_t)); Memcpy (buffer + wstrContent.length () * sizeof (wchar_t), fileBuf, nLen); Memcpy (buffer + wstrContent.length () * sizeof (wchar_t) + nLen, wstrLastLine.c_str (), wstrLastLine.length () * sizeof (wchar_t)); HRequest = HttpOpenRequest (h session, l "post", l "/ services / upload /", l "http / 1.1", zero, zero, 0, zero); If (hRequest) {bRet = HttpAddRequestHeaders (hRequest, wstrAddHeaders.c_str), wstrAddHeaders.length (), HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE); If (BRET) {BRT = HTTPS and RAJIST (HREIST, NOUL, 0, (* Zero * buffer, SSL size); If (BRT) {while (true) {variable buffer [1024] = {0}; Read DWORD = 0; BOOL r = InternetReadFile (hRequest, buffer, 1024, read more); If (Read! = 0) {wstring strUploadXML = buffer; break; }}}}  

I am not sure that I am adding image data to the string and posting the request. Do I need to convert image data to Unicode? Any suggestion, if someone finds me what I am doing that would be very useful to me.

Actually we can not send the posted content as Unicode, we can use Unicode in the Wininet API You can use the header in the form.

Once we read image data in four * buffers, we can add that buffer to the post content string and then add the last line of content.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -