{"id":3955,"date":"2020-04-20T12:40:24","date_gmt":"2020-04-20T11:40:24","guid":{"rendered":"https:\/\/help.cirrus-shield.com\/docs\/developer-guide\/rest-api\/upload-file\/"},"modified":"2022-01-11T09:43:00","modified_gmt":"2022-01-11T08:43:00","slug":"upload-file","status":"publish","type":"docs","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/upload-file\/","title":{"rendered":"6. Upload File"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li><strong><span class=\"has-inline-color has-luminous-vivid-orange-color\"><u>URL:<\/u> <\/span><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\u00ab \/RestApi\/UploadFile\u00bb<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><span class=\"has-inline-color has-luminous-vivid-orange-color\"><u>Method:<\/u>\u00a0<\/span><\/strong>POST<\/li><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">URL Params:<\/span><\/u><\/strong><ul><li>authToken [string] [Required]=the authentication token<\/li><li>fileName [string] [Required]=the name of the file that the user wants to upload<\/li><li>objectName [string] [Required]=the name of the record\u2019s object that the user wants to upload the file to<\/li><li>fieldName [string] [Required]=the API name of the field that the file will be uploaded to<\/li><li>RecGUID [long] [Required]=the record Id in CirrusShield that the file will be uploaded to<\/li><\/ul><\/li><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">Data Params:<\/span><\/u><\/strong><ul><li>dataStream =the data of the uploaded file<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get file name\n\n$fileName = $_FILES&#91;'file_upl']&#91;'name'];\n\/\/ Get file content\n\n$data = file_get_contents($_FILES&#91;'file_upl']&#91;'tmp_name']);\n\/\/ Transform file content to json array\n\n$array = array();\n\nforeach(str_split($data) as $char){\narray_push($array, ord($char));\n}\n\/\/ Send the Data Params\n\ncurl_setopt($client, CURLOPT_POSTFIELDS, \"=\".json_encode($array));\n&lt;form name=\"file_up\" action=\"UploadFile.php\" method=\"POST\" enctype=\"multipart\/form-data\">\nUpload your file here\n\n&lt;input type=\"file\" name=\"file_upl\" id=\"file_upl\"\/>\n\n&lt;input type=\"submit\" name=\"action\" value=\"submit\"\/>\n&lt;\/form><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">Success Response :<\/span><\/u><\/strong><ul><li>Status Code=200 (OK)<\/li><\/ul><\/li><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">Error Response:<\/span><\/u><\/strong><ul><li>Status Code=400 (BadRequest) (in case there is an error in the json data sent in the HTTP Post Request body or if the object name, API field name in the object or record id are wrong)<\/li><\/ul><\/li><\/ul>\n","protected":false},"author":12,"featured_media":0,"parent":944,"menu_order":5,"comment_status":"open","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_tag":[],"class_list":["post-3955","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/comments?post=3955"}],"version-history":[{"count":3,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3955\/revisions"}],"predecessor-version":[{"id":4038,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3955\/revisions\/4038"}],"up":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/944"}],"next":[{"title":"7. DownloadFile","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/downloadfile\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/6535"}],"prev":[{"title":"5. Data Action","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/data-action\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3954"}],"wp:attachment":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/media?parent=3955"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/doc_tag?post=3955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}