How to upload an html form containing a pdf file from an extension written in JavaScript to a URL?
I need to send a form from an Adobe Illustrator extension to a URL.
Previously we were using C++ to write the plugin with same functionality for InDesign.
To implement it as an extension for Photoshop and Illustrator we used HTML5 for UI, JQuery, AngularJS to implement functionalities of the extension.
Now I need to send a PDF to a URL in a form of HTML FORM.
We were using cURL for C++ for this purpose. What can we use with JS to do the same here?
I tried to use Ajax but it turned out that you cannot make a cross-domain call with it, and my extension doesn't have a domain name or IP or anything. Its just an extension running with Photoshop and Illustrator and we need to upload a form (containing a PDF) to a URL.
How can I do it?
Any help will be appreciated. I have added the C++ code for this function below.
| bool WPConnection::UploadPDFToServer( const char* pdfPath, const char* urlInfo ) | |
| { |
bool16 uploadStatus = false;
try // Abhishek
{
| // Get the URL | |
| char connectionURL[256] = {0}; |
| // Now update the project panel tree | |
| const char* userName = g_WPDetailsVector.at(0).c_str(); | |
| const char* passWord = g_WPDetailsVector.at(1).c_str(); | |
| const char* projectID = g_WPDetailsVector.at(2).c_str(); | |
| const char* statusID = g_WPDetailsVector.at(3).c_str(); | |
| const char* pageNumber = g_WPDetailsVector.at(4).c_str(); |
| strcpy(connectionURL, urlInfo); | |
| strcat(connectionURL, "/indd_filetransfer.asp?"); | |
| strcat(connectionURL, "username="); | |
| strcat(connectionURL, userName); | |
| strcat(connectionURL, "&password="); | |
| strcat(connectionURL, passWord); | |
| strcat(connectionURL, "&project_id="); | |
| strcat(connectionURL, projectID); | |
| strcat(connectionURL, "&status_id="); | |
| strcat(connectionURL, statusID); | |
| strcat(connectionURL, "&item_numbers="); | |
| strcat(connectionURL, pageNumber); |
| CURLcode result = CURLE_FAILED_INIT; | ||||
| struct curl_httppost *formpost=NULL; | ||||
| struct curl_httppost *lastptr=NULL; | ||||
| curl_formadd(&formpost, | ||||
| &lastptr, | ||||
| CURLFORM_COPYNAME, "file", | ||||
| CURLFORM_FILE, pdfPath, | ||||
| CURLFORM_CONTENTTYPE, "pdf", | ||||
| CURLFORM_END); |
| if(fCurl) | ||||
| { | ||||
| // Clearing all the connection info | ||||
| this->ClearConnectionInfo(); | ||||
| //set options for a curl easy handle | ||||
| curl_easy_setopt(fCurl, CURLOPT_URL, connectionURL); | ||||
| curl_easy_setopt(fCurl, CURLOPT_HTTPPOST, formpost); | ||||
| result = curl_easy_setopt (fCurl, CURLOPT_NOPROGRESS, FALSE); | ||||
| result = curl_easy_setopt (fCurl, CURLOPT_PROGRESSFUNCTION, progress_callback); | ||||
| //Don't verify the peer. | ||||
| curl_easy_setopt(fCurl, CURLOPT_SSL_VERIFYPEER, FALSE); | ||||
| //Use proxy information | ||||
| if( g_UseProxy == kTrue ) | ||||
| { | ||||
| curl_easy_setopt( fCurl, CURLOPT_PROXY, g_WPDetailsVector.at(5).c_str() ); | ||||
| if( g_ProxyAuthentication == kTrue ) | ||||
| { | ||||
| curl_easy_setopt( fCurl, CURLOPT_PROXYUSERPWD, g_WPDetailsVector.at(6).c_str() ); | ||||
| } | ||||
| } |
| result = curl_easy_perform(fCurl); | ||
| this->GetConnectionInfo(fCurl); |
| curl_formfree(formpost); | ||
| } |
| if( (result == CURLE_OK) && (fHttpStatus == 200) /*&& (fResponseStatus == -1)*/) | ||
| { | ||
| g_UploadPercent = 100; | ||
| uploadStatus = true; | ||
| } | ||
| else | ||
| { | ||
| g_UploadError = true; | ||
| } |
}
catch(...)
{
| g_UploadError = true; |
}
return uploadStatus;
| } |
