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 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算