仅通过Auth Middleware和基于令牌的身份验证访问存储文件夹中的文件(Access files in storage folder only through Auth Middleware and Token based authentication)
我在Laravel网站上有以下文件夹。
/存储/资产/媒体
此文件夹可以包含以下信息
/storage/Asset/Media/1/abc.png
/storage/Asset/Media/2/abc.png
这里1或2是文件夹名称。
我有以下代码来保护文件夹,以便没有人可以访问该文件夹而无需身份验证
Route::group(['middleware' => ['web', 'auth']], function () { Route::get('/storage/Asset/Media/{ID}/{eded}', array( 'as' => 'Files', 'uses' => 'User\Account\Media\MediaController@DownloadMedia', )); });
因此,在用户的会话未在浏览器中过期之前,没有人可以访问这些文件。
问题出现在Android中,因此现在没有人可以访问由于Auth Middleware而导致的文件。
有人可以建议这样的方法,可以通过基于令牌的身份验证(通过Android)和使用Auth Controller(通过网站)下载文件吗?
I have following folder in my Laravel website.
/storage/Asset/Media
This folder can have info like below
/storage/Asset/Media/1/abc.png
/storage/Asset/Media/2/abc.png
Here 1 or 2 is the folder names.
I have following code to secure the folder so that nobody can access the folder without authentication
Route::group(['middleware' => ['web', 'auth']], function () { Route::get('/storage/Asset/Media/{ID}/{eded}', array( 'as' => 'Files', 'uses' => 'User\Account\Media\MediaController@DownloadMedia', )); });
so in this way nobody can access the files until user's session is not expired in a browser.
Issue is in Android, so now nobody can access the files due to Auth Middleware.
Can somebody suggest the approach such that, files can be accessible to download via Token Based Authentication(through Android) and also using Auth Controller(through Website)?
原文:https://stackoverflow.com/questions/37372317
最满意答案
JAX-RS提供程序只需要为
MultivaluedMap<String,String>
提供application/x-www-form-urlencoded
映射。 而且我很确定开箱即用的Jersey不会从application/x-www-form-urlencoded
到常规POJO提供额外的映射器。 您可以编写自己的客户端提供程序,但根据您需要执行此操作的频率,将POJO字段自己映射到URL字段可能更简单。JAX-RS providers are only required to provide mappings to
application/x-www-form-urlencoded
forMultivaluedMap<String,String>
. And I'm pretty sure that out-of-the-box Jersey doesn't provide an additional mapper fromapplication/x-www-form-urlencoded
to regular POJOs. You could write your own client side provider, but depending on how often you need to do this it may be simpler to just map the POJO fields to the URL fields yourself.
相关问答
更多-
我认为你可以同时使用这个(JAX-RS实体提供者)和这个(使用Jackson和Jersey) ,以实现你想要的。 简而言之,注册一个使用@Produces("application/vnd.stupidNameThatReallyIsJustJSON+json")注释的MessageBodyWriter ,并且在实现中只需将编组/解组委派给Jackson。 编辑:尝试沿线的东西 package my.pack.age; import com.sun.jersey.core.provider.Abstrac ...
-
如果您的Web服务生成JSON,则必须使用accept()方法处理客户端中的JSON: ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).post(searchQuery, MediaType.APPLICATION_JSON); ListWrapper listWrapper = response.getEntity(ListWrapper.class); 试试这个,并给你的结果。 If your web-s ...
-
Spring MVC RestFul服务+ Jersey客户端400错误请求(Spring MVC RestFul service + Jersey Client 400 Bad Request)[2022-04-11]
我认为你告诉你在有效负载中发送JSON的服务,但是当你这样做时,你发送的是表格参数: form.param("id", "jersey"); 以及以下几行,您正在模拟POST,就像创建带有提交按钮的HTML表单一样。 您可能必须在客户端声明一个类User,实例是此类的一个对象,并将属性填充为: User user = new User(); user.setId("jersey"); 然后在POST中发送这个对象(我没有使用Invocation.Builder但它确实有一些post对象作为参数的post ... -
你不使用ClientResponse 。 你应该使用Response 。 当你希望响应实体自动反序列化时,你只需要使用.post()的第二个参数。 当你不使用第二个参数时,返回类型是Response 。 然后你可以用Response#readEntity()读取/反序列化实体 Response response = target .request(MediaType.TEXT_PLAIN) .post(Entity.form(form)); String data = response.r ...
-
我终于得到了两个改变: 在查看此处的示例后,我将此init-param添加到web.xml的AtmosphereServlet以解决Tomcat中的text/plain问题:
org.atmosphere.websocket.messageContentType application/json -
我通过发布一个InputStream而不是长JSON字符串解决了这个问题。 I solved this problem by posting an InputStream instead of long JSON string.
-
JAX-RS有一个MultivaluedMap接口,在Jersey中有一个'MultivaluedMapImpl'。 Client client = Client.create(); WebResource webResource = client.resource("http://site.com/resource"); MultivaluedMap
map = new MultivaluedMapImpl(); map.put("loginId", loginId); . ... -
我找到了罪魁祸首。 我的域类是由构建器创建的,因此具有私有构造函数。 这引发了这个问题。 提供公共构造函数解决了这个问题。 单个对象示例工作,因为它实际上是在另一个具有公共构造函数的域类上测试的。 由于我没有看到连接并想到在这里简化描述 - 我只展示了一个域类 I have found the culprit. My domain class is created by a builder and therefore has a private constructor. This provoked the ...
-
我设法让客户端的东西工作。 问题是我强制将文件作为单独的消息正文部分发送,而x-www-form-urlencoded实际上将所有数据作为参数打包在整个正文的查询中 。 因此,如果您想通过Jersey post方法发送附件,那么正常工作的客户端代码将是: ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource webResource = client.resourc ...
-
JAX-RS提供程序只需要为MultivaluedMap
提供application/x-www-form-urlencoded映射。 而且我很确定开箱即用的Jersey不会从application/x-www-form-urlencoded到常规POJO提供额外的映射器。 您可以编写自己的客户端提供程序,但根据您需要执行此操作的频率,将POJO字段自己映射到URL字段可能更简单。 JAX-RS providers are only required to provide map ...