2017-10-13 12 views

답변

1

주와 같이 코드에서 링크를 인쇄해야 스크립트

$user = "admin" 
$pass= "admin" 
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force 
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd) 
$body = "file=$(get-content c:\myupload.zip -raw)" 
$targetname = "myupload.zip" 
$oc = "http://myowncloud:8085/remote.php/webdav/NOC/" 
Invoke-RestMethod -uri $oc$targetname -method Put -body $body -Credential $credential 

입니다 명시 적으로 그렇게하십시오. 이렇게하려면 ocs Share API을 사용해야합니다. 문서에서 공개 링크 공유 (예 : shareType = 3)의 경우 파일 과 함께 POST 요청을 별도로 수행해야합니다. 또한

# Upload the file 
$body = $(get-content c:\test.txt -raw) 
$targetname = "test.txt" 
$oc = "http://demo.owncloud.com/" 
$dav_endpoint = "remote.php/dav/files/admin/" 
Invoke-RestMethod -Uri $oc$dav_endpoint$targetname -Method Put -Body $body -Credential $credential 

# Create a public share for that file: 
$headers = @{"Ocs-APIREQUEST"="true"} 
$sharing_api = "ocs/v1.php/apps/files_sharing/api/v1/shares?format=json" 

# Required parameters to create the share: 
$body = @{ 
    path = "/$($targetname)" 
    shareType = "3" 
} 

$response = Invoke-RestMethod -Uri $oc$sharing_api -Method Post -Headers $headers -Body $body -Credential $credential 
# Print the public link URL: 
echo $response.ocs.data.url 

이 유일한 것으로 고려 :

나는 약간 더 나은 URL 조성물은 허용 할 수도 ownCloud의 새로운 인스턴스 (. 버전 9 등 서열 come with a different WebDAV endpoint)과 협력하게 코드를 적용했습니다 해피 경로을 다루고 각 요청에서 HTTP 상태를 확인하는 경우 &이 더 정확합니다 ...

+0

퍼블릭 공유 부분을 올리거나 올리면 업로드 할 수 있지만 공개 링크 URL은 인쇄되지 않습니다. –

+0

@JaydeepChaudhari woop, typo; 죄송합니다. '$ response.ocs.data.url'로 다시 시도하십시오. – Alfageme

+0

예, 이미 알고 있습니다. 고마워요 :) –