从 Web 应用程序将文件上传到云端

发布于 2024-10-28 12:02:07 字数 1038 浏览 5 评论 0原文

我需要将文件从 HTML 5 应用程序(在桌面/移动/平板设备中使用)(没有服务器端)上传到在线存储。任何存储都可以,但此时最好使用免费服务。需要的工作流程是:

上传文件到存储->上传文件。获取文件的公共 URL ->使用 facebook 的 API 共享 facebook 中的公共 URL。

facebook 部分我已经涵盖了,但我需要某个地方来放置我的文件。我尝试使用 box.net API,但由于发出跨站点请求而出现错误:(

http://developers.box.net/w/page/12923936/ApiFunction_get_ticket

function get_ticket(api_key){
   $.ajax({
      url: 'https://www.box.net/api/1.0/rest?action=get_ticket&api_key=' + api_key,
      success: function(response){
         console.log(response);
      }
   });
}

在 chrome 控制台中产生:

XMLHttpRequest cannot load https://www.box.net/api/1.0/rest?action=get_ticket&api_key=(my_key). Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.
GET https://www.box.net/api/1.0/rest?action=get_ticket&api_key=ynu54ytflrz9fzpdzy5raf1hc1rmed9i undefined (undefined)

任何解决方法在这个问题上将受到极大的欢迎。

I need to upload files from an HTML 5 application (used in desktop/mobile/tablet device)(there's no server side) to an online storage. Any storage would be fine, still, using a free service would be preferred at this point. The needed workflow is:

upload file to a storage -> get file's public URL -> share the public URL in facebook with facebook's API.

The facebook part I've got it covered but I need somewhere to put my files in. I tried using box.net API but I get error due to the cross-site request being made:

( http://developers.box.net/w/page/12923936/ApiFunction_get_ticket )

function get_ticket(api_key){
   $.ajax({
      url: 'https://www.box.net/api/1.0/rest?action=get_ticket&api_key=' + api_key,
      success: function(response){
         console.log(response);
      }
   });
}

yields in the chrome console:

XMLHttpRequest cannot load https://www.box.net/api/1.0/rest?action=get_ticket&api_key=(my_key). Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.
GET https://www.box.net/api/1.0/rest?action=get_ticket&api_key=ynu54ytflrz9fzpdzy5raf1hc1rmed9i undefined (undefined)

Any workaround on this issue will be most welcomed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愿与i 2024-11-04 12:02:07

经过一番研究,问题在于 JS 无法与不同于下载源的域进行交互。

这就是为什么您无法将 FB JS 库下载到您的域,而是每次都从他们的网站加载它。这也是为什么我无法做我在问题中尝试做的事情。

如果您有关于此问题的更多详细信息,请随时添加我的解释:)

The problem there, after some research, is that JS cannot interact with a domain different from the one it was download from.

That's why you cannot download the FB JS library to your domain but instead load it from their website every time. That's also why I'm not able to do what I've tried to do in the question.

Feel free to add up to my explanation if you've got any more details on this issue:)

倾城月光淡如水﹏ 2024-11-04 12:02:07

控制台中的错误显示:

Access-Control-Allow-Origin 不允许来源 http://localhost:8000。< /代码>


也许您可以尝试将您的应用程序上传到其未来的服务器。

The error in the console says:

Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.

Maybe you could try uploading your application to its future server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文