{"id":1052,"date":"2019-06-26T16:44:38","date_gmt":"2019-06-26T07:44:38","guid":{"rendered":"https:\/\/oboki.net\/workspace\/?p=1052"},"modified":"2019-09-01T22:19:50","modified_gmt":"2019-09-01T13:19:50","slug":"upload-files-through-api","status":"publish","type":"post","link":"https:\/\/oboki.net\/workspace\/nextcloud\/upload-files-through-api\/","title":{"rendered":"[Nextcloud] Upload files through API"},"content":{"rendered":"<h1>Upload files through API<\/h1>\n<blockquote><p>\nAPI \ub97c \uc774\uc6a9\ud574\uc11c nextcloud\uc5d0 \ub514\ub809\ud1a0\ub9ac\ub97c \uc0dd\uc131\ud558\uace0 \ud30c\uc77c\uc744 \uc5c5\ub85c\ub4dc\ud560 \uc218 \uc788\ub2e4.\n<\/p><\/blockquote>\n<p>\uc9c0\uae08 \uc6b4\uc601\ud558\uace0 \uc788\ub294 nextcloud\ub294 \uc11c\ubc84 \ud55c \ub300\uc5d0 \ub514\uc2a4\ud06c\ub3c4 \uc804\ubd80 \ud55c \uc7a5\uc529 \uc2f1\uae00\ub85c \ub3cc\uc544\uac00\uace0 \uc788\uc9c0\ub9cc \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc5ec\ub7ec \ub300 \uc788\uae30 \ub54c\ubb38\uc5d0 \uad73\uc774 \ub370\uc774\ud130\uc5d0 \ub300\ud55c \ubc31\uc5c5\uc774\ub098 \uac00\uc6a9\uc131\uc744 \uc124\uc815\ud560 \ud544\uc694\ub294 \uc5c6\ub2e4. \ub300\uc2e0 \uc6f9\uc11c\ubc84\ub791 \uba54\ud0c0\ub370\uc774\ud130\uc5d0 \ub300\ud55c \ubc31\uc5c5\uc740 \ubcc4\ub3c4\ub85c \ud544\uc694\ud55c\ub370 \uc774 API\ub97c \uc774\uc6a9\ud558\uba74 \uc6f9\uc11c\ubc84 \ub364\ud504\ub97c \ub370\uc774\ud130\ud654 \uc2dc\ucf1c\uc11c nextcloud\uc5d0 \uc800\uc7a5\ud560 \uc218 \uc788\ub2e4.<\/p>\n<h2><a href=\"https:\/\/docs.nextcloud.com\/server\/latest\/user_manual\/files\/access_webdav.html#accessing-files-using-curl\">Accessing files using cURL<\/a><\/h2>\n<h3>get the properties of files<\/h3>\n<p>\ub2e4\uc74c API\ub97c \uc774\uc6a9\ud574\uc11c \ud2b9\uc815 \uacbd\ub85c\uc758 \uc0ac\uc6a9\ub7c9\uc774\ub098 \ucd5c\uc885 \uc218\uc815 \uc77c\uc790\uc5d0 \ub300\ud55c \uc815\ubcf4\ub97c \uc5bb\uc5b4\uc62c \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\">curl -X PROPFIND -H &quot;Depth: 1&quot; -u user:pass https:\/\/example.com\/nextcloud\/remote.php\/dav\/files\/USERNAME\/<\/code><\/pre>\n<h3>create a folder<\/h3>\n<p>\ub2e4\uc74c\uacfc \uac19\uc774 API\ub97c \uc774\uc6a9\ud574\uc11c \ub514\ub809\ud1a0\ub9ac\ub97c \uc0dd\uc131\ud558\uac70\ub098<\/p>\n<pre><code class=\"language-bash\">curl -u user:pass -X MKCOL &quot;https:\/\/example.com\/nextcloud\/remote.php\/dav\/files\/USERNAME\/$(date &#039;+%d-%b-%Y&#039;)&quot;<\/code><\/pre>\n<h3>upload a file<\/h3>\n<p>\ud30c\uc77c\uc744 \uc5c5\ub85c\ub4dc\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\">curl -u user:pass -T error.log &quot;https:\/\/example.com\/nextcloud\/remote.php\/dav\/files\/USERNAME\/$(date &#039;+%d-%b-%Y&#039;)\/error.log&quot;<\/code><\/pre>\n<h2>Sample bash script<\/h2>\n<pre><code class=\"language-bash\">NC_HOSTNAME=&quot;https:\/\/example.com\/nextcloud&quot;\nNC_USERNAME=&quot;oboki&quot;\nNC_PASSWORD=&quot;password&quot;\n\nUPLOAD_FILE=&quot;www.tar.gz.$(date &#039;+%Y%m%d%H%M%S&#039;)&quot;\nFILE_DIR=$HOME\n\nNC_DIR=&quot;backups\/example.com\/webserver\/$(date &#039;+%Y-%m-%d&#039;)&quot;\n\ncurl -s -u $NC_USERNAME:$NC_PASSWORD -X PROPFIND -H &quot;Depth: 1&quot; \\\n&quot;${NC_HOSTNAME}\/remote.php\/dav\/files\/$NC_USERNAME\/$NC_DIR&quot; | grep &quot;200 OK&quot;\nRES=$(echo $?)\necho $RES\n\nif [ $RES -eq 0 ]; then\n    echo &quot;Target directory already exist.&quot;\nelse\n    curl -s -u $NC_USERNAME:$NC_PASSWORD -X MKCOL \\\n    &quot;${NC_HOSTNAME}\/remote.php\/dav\/files\/$NC_USERNAME\/$NC_DIR&quot; | grep &quot;\\S&quot;\n    RES=$(echo $?)\n    if [ $RES -eq 0 ]; then\n        echo &quot;Failed to create target directory&quot;\n        exit 1\n    fi\nfi\n\ncd \/var\/\ntar -czf ${FILE_DIR}\/${UPLOAD_FILE} www\nRES=$(echo $?)\necho $RES\n\nif [ $RES -eq 0 ]; then\n    curl -s -u $NC_USERNAME:$NC_PASSWORD -T $FILE_DIR\/$UPLOAD_FILE \\\n    &quot;${NC_HOSTNAME}\/remote.php\/dav\/files\/$NC_USERNAME\/$NC_DIR\/$UPLOAD_FILE&quot; | grep &quot;\\S&quot;\n    RES=$(echo $?)\n    if [ $RES -eq 0 ]; then\n        echo &quot;Failed to upload&quot;\n        exit 1\n    fi\nfi\n\nrm $FILE_DIR\/$UPLOAD_FILE<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Upload files through API API \ub97c \uc774\uc6a9\ud574\uc11c nextcloud\uc5d0 \ub514\ub809\ud1a0\ub9ac\ub97c \uc0dd\uc131\ud558\uace0 \ud30c\uc77c\uc744 \uc5c5\ub85c\ub4dc\ud560 \uc218 \uc788\ub2e4. \uc9c0\uae08 \uc6b4\uc601\ud558\uace0 \uc788\ub294 nextcloud\ub294 \uc11c\ubc84 \ud55c \ub300\uc5d0 \ub514\uc2a4\ud06c\ub3c4 \uc804\ubd80 \ud55c \uc7a5\uc529 \uc2f1\uae00\ub85c \ub3cc\uc544\uac00\uace0 \uc788\uc9c0\ub9cc \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc5ec\ub7ec \ub300 \uc788\uae30 \ub54c\ubb38\uc5d0 \uad73\uc774 \ub370\uc774\ud130\uc5d0 \ub300\ud55c \ubc31\uc5c5\uc774\ub098 \uac00\uc6a9\uc131\uc744 \uc124\uc815\ud560 \ud544\uc694\ub294 \uc5c6\ub2e4. \ub300\uc2e0 \uc6f9\uc11c\ubc84\ub791 \uba54\ud0c0\ub370\uc774\ud130\uc5d0 \ub300\ud55c \ubc31\uc5c5\uc740 \ubcc4\ub3c4\ub85c \ud544\uc694\ud55c\ub370 \uc774 API\ub97c \uc774\uc6a9\ud558\uba74 \uc6f9\uc11c\ubc84 \ub364\ud504\ub97c \ub370\uc774\ud130\ud654 \uc2dc\ucf1c\uc11c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[158],"tags":[],"class_list":["post-1052","post","type-post","status-publish","format-standard","hentry","category-nextcloud"],"_links":{"self":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/1052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/comments?post=1052"}],"version-history":[{"count":3,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/1052\/revisions"}],"predecessor-version":[{"id":1158,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/1052\/revisions\/1158"}],"wp:attachment":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/media?parent=1052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/categories?post=1052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/tags?post=1052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}