dongmo6937 2016-05-30 10:33
浏览 124
已采纳

(Laravel)在数据库中保存表单请求文件

Explanation of my process:

When a user fills in a form of mine and uploads it, it doesn't get uploaded to a database. It gets uploaded to a web based third party app that contains all our client information. This app however has a rate limit as a security, and since i can't let the customer who fills out the form know that, i need to temporarily save the data to my database.

I already have this up and running like i want it. There is a problem though.

Problem:

If the form contains a file, the file won't get uploaded to the database, because laravel does not allow serialization of UploadFile objects. Which is fair since all that would do is upload the directory of a temporary file to the database, so that wouldn't work.

Either way, the API expects the file body to be multipart/form-data so i wouldn't be able to get that from the database.

The solution?

Is it be possible to save the file locally and redo the request somehow without manually filling out the form again?

I realize this request is a bit odd, but I'm sure the idea of saving a request temporarily in a database for later use is very good knowledge.

  • 写回答

1条回答 默认 最新

  • doutuan6158 2016-06-09 09:08
    关注

    To close this question I went with Ben Swinburne's suggestion of using guzzle.

    What i did was save the file locally using the Input::file('input')->move('destination', 'filename') function

    I then later call the database using a cron job to check for requests. Guzzle then makes a request to the original POST url and uploads the entire thing.

    Guzzle code:

    $fileresponse = Guzzle::post('/path/to/POST', [ 'multipart' => $arrayOfValues ] );

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?