简体   繁体   English

不允许使用AWS 405方法

[英]AWS 405 Method not allowed

I've been banging my head against the wall with this for a few hours now and I can't seem to figure out what's wrong. 我已经用这个把我的头撞在墙上好几个小时了,但我似乎无法弄清楚出了什么问题。

Basically I have a S3 Bucket and I'm trying to upload a simple text (.txt) file to it from Unity3D. 基本上,我有一个S3存储桶,我正尝试从Unity3D向其中上传一个简单的文本(.txt)文件。 The C# script to download and PHP script are taken from here 此处获取要下载的C#脚本和PHP脚本

So I put the PHP script in the bucket itself, get the URL of that php script and call it from the C# code: 因此,我将PHP脚本放入了存储桶本身,获取了该php脚本的URL,然后从C#代码进行调用:

PHP script: PHP脚本:

<?php
   if(isset($_FILES['theFile']))
   {
      print("Success! ");
      print("tmpName: " . $_FILES['theFile']['tmp_name'] . " ");
      print("size: " . $_FILES['theFile']['size'] . " ");
      print("mime: " . $_FILES['theFile']['type'] . " ");
      print("name: " . $_FILES['theFile']['name'] . " ");


   move_uploaded_file($_FILES['theFile']['tmp_name'], "../images/" . $_FILES['theFile']['name']);

   } else
   {
      print("Failed!");
   }
?>

C#: C#:

 WWWForm postForm = new WWWForm();
 postForm.AddBinaryData("theFile", bytes, "TestFile", "text/plain");
 WWW upload = new WWW(phpScriptURL, postForm);        
 yield return upload;
 if (upload.error == null)
     Debug.Log("upload done :" + upload.text);
 else
     Debug.Log("Error during upload: " + upload.error);

I get the error "Error during upload: 405 Method not allowed" 我收到错误“上传期间出错:405方法不允许”

I tried changing permission settings, Region settings, etc but to no avail. 我尝试更改权限设置,区域设置等,但无济于事。

I read this answer and it mentioned to change the end point but I can't seem to do that there's no way to edit it. 我读了这个答案 ,它提到要更改终点,但我似乎无法做到这一点,无法对其进行编辑。

If I try the same PHP/C# script on a different server it works fine... But just not in the S3 Bucket. 如果我在不同的服务器上尝试相同的PHP / C#脚本,则可以正常工作……但不能在S3存储桶中使用。

I've tried another PHP/C# script and got the same result, same error on the S3 bucket but success on a different server. 我尝试了另一个PHP / C#脚本,并在S3存储桶上获得了相同的结果,相同的错误,但在另一台服务器上获得了成功。

Here's the other PHP script I tried: 这是我尝试过的其他PHP脚本:

<?php
$data = file_get_contents('php://input');
try {
    $result = file_put_contents("save-bytes.txt", $data, FILE_APPEND);
} catch (Exception $e) {
    echo $e->getMessage();
    die();
}
if ($result !== false)
{
    echo "Saved " . $result . " bytes";
} else {
    echo "Data is not saved";
}

(The C# code used with this script does something similar to the previously posted C# code) (与此脚本一起使用的C#代码与以前发布的C#代码具有相似的功能)

Thanks for any help in advance 感谢您的任何帮助

S3 buckets are locked down to private by default. 默认情况下,S3存储桶被锁定为私有。 You have to edit the access policy on the bucket if you want to put files into it. 如果要将文件放入存储桶中,则必须编辑访问策略。 For information on S3 bucket policies check out the docs . 有关S3存储桶策略的信息, 请查看docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM