Copied
$fileOperations = new FileOperations();
$bodyWrapper = new BodyWrapper();
$streamWrapper = new StreamWrapper(null, null, "/Users/username/Desktop/py.html");
$streamWrapper1 = new StreamWrapper(null, null, "/Users/username/Desktop/download.png");
$streamWrapper2 = new StreamWrapper(null, null, "/Users/username/Desktop/samplecode.txt");
$bodyWrapper->setFile([$streamWrapper, $streamWrapper1, $streamWrapper2 ]);
$paramInstance = new ParameterMap();
$response = $fileOperations->uploadFiles($bodyWrapper, $paramInstance);
Copied<?php
class UploadFilestoZohoFileSystem
{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$curl_options[CURLOPT_URL] = "https://www.zohoapis.com/crm/v2.1/files";
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "POST";
$fileName = "asdad.zip";
$filePath = "/Users/test/PHP/PHPNativeSampleCode/asdad.zip";
$file = fopen($filePath, "rb");
$fileData = fread($file, filesize($filePath));
$date = new \DateTime();
$current_time_long= $date->getTimestamp();
$lineEnd = "\r\n";
$hypen = "--";
$contentDisp = "Content-Disposition: form-data; name=\""."file"."\";filename=\"".$fileName."\"".$lineEnd.$lineEnd;
$data = utf8_encode($lineEnd);
$boundaryStart = utf8_encode($hypen.(string)$current_time_long.$lineEnd) ;
$data = $data.$boundaryStart;
$data = $data.utf8_encode($contentDisp);
$data = $data.$fileData.utf8_encode($lineEnd);
$boundaryend = $hypen.(string)$current_time_long.$hypen.$lineEnd.$lineEnd;
$data = $data.utf8_encode($boundaryend);
$curl_options[CURLOPT_POSTFIELDS]= $data;
$headersArray = array();
$headersArray = ['ENCTYPE: multipart/form-data','Content-Type:multipart/form-data;boundary='.(string)$current_time_long];
$headersArray[] = "content-type".":"."multipart/form-data";
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " ."1000.30f3a589XXXXXXXXXXXXXXXXXXX4077.dc5XXXXXXXXXXXXXXXXXXXee9e7c171c";
var_dump($data);
$curl_options[CURLOPT_HTTPHEADER]=$headersArray;
curl_setopt_array($curl_pointer, $curl_options);
$result = curl_exec($curl_pointer);
$responseInfo = curl_getinfo($curl_pointer);
curl_close($curl_pointer);
list ($headers, $content) = explode("\r\n\r\n", $result, 2);
if(strpos($headers," 100 Continue")!==false){
list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
}
$headerArray = (explode("\r\n", $headers, 50));
$headerMap = array();
foreach ($headerArray as $key) {
if (strpos($key, ":") != false) {
$firstHalf = substr($key, 0, strpos($key, ":"));
$secondHalf = substr($key, strpos($key, ":") + 1);
$headerMap[$firstHalf] = trim($secondHalf);
}
}
$jsonResponse = json_decode($content, true);
if ($jsonResponse == null && $responseInfo['http_code'] != 204) {
list ($headers, $content) = explode("\r\n\r\n", $content, 2);
$jsonResponse = json_decode($content, true);
}
var_dump($headerMap);
var_dump($jsonResponse);
var_dump($responseInfo['http_code']);
}
}
(new UploadFilestoZohoFileSystem())->execute();
Copied
fo = Files::FileOperations.new
bw = Files::BodyWrapper.new
pm = ParameterMap.new
pm.add(Files::FileOperations::UploadFileParam.type, 'inline')
sw1 = Util::StreamWrapper.new(nil, nil, '/Users/user_name/RUBYWS/zohocrm-rubysdk-sample-application/3524033000005520002.zip')
sw2 = Util::StreamWrapper.new(nil, nil, '/Users/user_name/RUBYWS/zohocrm-rubysdk-sample-application/3524033000005902005.zip')
files = [sw1, sw2]
bw.file = files
response = fo.upload_file(bw, pm)
Copiedrequire 'net/http'
require 'json'
class UploadFilestoZohoFileSystem
def execute
url = "https://www.zohoapis.com/crm/v2.1/files"
url = URI(url)
req = Net::HTTP::Post.new(url.request_uri)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
headers={}
headers["Authorization"]="Zoho-oauthtoken 1000.dfa7XXXXXXXXXXXXXXXXXX84f9665840.c176aeXXXXXXXXXXXX13f3d37a84d"
headers&.each { |key, value| req.add_field(key, value) }
file_path = "/Users/test/Desktop/pic.png"
file = File.open(file_path)
data=[["file",file.read, { filename: "pic.png" }]]
req.set_form(data,'multipart/form-data')
response=http.request(req)
status_code = response.code.to_i
headers = response.each_header.to_h
print status_code
print headers
unless response.body.nil?
print response.body
end
end
end
UploadFilestoZohoFileSystem.new.execute
CopiedfileVariable = invokeurl
[
url: "https://file-examples-com.github.io/uploads/2017/10/file-sample_150kB.pdf"
type: GET
];
fileVariable.setParamName("file");
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v2.1/files"
type :POST
files: fileVariable
connection:"crm_oauth_connection"
];
info response;