小编vfs*_*aki的帖子

AngularJs应用程序中的下载已损坏

我正在尝试使用FileSaver.js下载文件,但每当我点击下载按钮时,我都会收到损坏的文件.

App由PHP REST服务支持,并且从命令行使用cURL确认REST正常工作.

这是我用于下载的伪代码的最后一个版本:

// Let str be the data received from $http promise
// This code is run in a "then" callback

var arr= new Uint8Array(str.length);
for(var i=0; i<str.length; i++) {
    arr[b]=str.charCodeAt(i);
};
var blob = new Blob([arr], {type: 'application/octet-stream'});
saveAs(blob, "AFileName");
Run Code Online (Sandbox Code Playgroud)

它只会破坏文件.

我也试过没有应用Uint8Array,并str直接给予Blob.正如你猜测的那样,它也失败了.

我自己在写服务器和客户端,所以我可以更改其中的任何内容.但问题是我想处理客户端下载,我只是无法将用户重定向到文件URL以下载它,因为REST需要身份验证,而且该令牌只存在于Angular应用程序中.在没有身份验证的情况下更改服务器只是为了处理文件下载不是一个好的选择.

REST具有/files/:id访问时的URL ,将文件内容作为常规HTTP文件下载(如上所述使用cURL进行测试).可能$http是问题?以某种方式强制对接收的数据进行某种编码或某些假设.无论如何,我在Angular方面没有多少经验.

javascript download angularjs

5
推荐指数
1
解决办法
2998
查看次数

如何正确测试GenServer中的handle_cast?

我有一个GenServer,它负责联系外部资源。调用外部资源的结果并不重要,偶尔的失败是可以接受的,因此使用handle_cast似乎适合代码的其他部分。我确实有一个用于该外部资源的类似接口的模块,并且我正在使用一台 GenServer 来访问该资源。到目前为止,一切都很好。

但是当我尝试为此 gen_server 编写测试时,我不知道如何测试handle_cast. 我有 GenServer 的接口函数,我尝试测试这些函数,但它们总是返回:ok,除非 GenServer 没有运行。我无法测试这一点。

我稍微改变了代码。我将代码抽象handle_cast到另一个函数中,并创建了一个类似的handle_call回调。然后我就可以handle_call轻松地进行测试,但这有点像黑客。

我想知道人们通常如何测试异步代码,就像这样。我的方法正确或者可以接受吗?如果没有,那该怎么办?

testing erlang elixir erlang-otp gen-server

4
推荐指数
1
解决办法
1239
查看次数

Laravel登录后重定向

这是文档

成功验证用户身份后,他们将被重定向到/homeURI。您可以通过定义一个定制后的验证重定向位置redirectTo的财产LoginControllerRegisterController以及ResetPasswordController

protected $redirectTo = '/';

如果重定向路径需要自定义生成逻辑,则可以定义redirectTo方法而不是 redirectTo属性:

protected function redirectTo() { // }

所以我定义了

protected function redirectTo()
{
    if (\Auth::user()->isAdmin()) {
        return '/dashboard';
    } else {
        return '/home';
    }
}
Run Code Online (Sandbox Code Playgroud)

但您可能会猜到,它不起作用。它总是重定向到/home

通过源,我发现了这一点

namespace Illuminate\Foundation\Auth;

trait AuthenticatesUsers
{
    ...

    /**
     * Send the response after the user was authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();

        $this->clearLoginAttempts($request); …
Run Code Online (Sandbox Code Playgroud)

php authentication laravel laravel-5.3

4
推荐指数
1
解决办法
1357
查看次数

您如何看待我的数据库架构?

我想我在设计的数据库架构中没有做到最好.

我也在使用MySQL;

我有2个主要表:IMEI和用户;

IMEI结构:

+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| imei    | varchar(20) | NO   | PRI | NULL    |       |
| user_id | int(11)     | NO   | MUL | NULL    |       |
+---------+-------------+------+-----+---------+-------+
Run Code Online (Sandbox Code Playgroud)

用户结构:

+-------+---------------+------+-----+---------+----------------+
| Field | Type          | Null | Key | Default | Extra          |
+-------+---------------+------+-----+---------+----------------+
| id    | int(11)       | NO   | PRI | NULL    | auto_increment |
| pass  | varchar(2000) | NO   | …
Run Code Online (Sandbox Code Playgroud)

mysql sql database

1
推荐指数
1
解决办法
276
查看次数