如何使用Scala在Play!2中提供上传的文件?

栏目: Scala · 发布时间: 7年前

内容简介:所述进行操作.这是代码:我不清楚如何将上传的图像提供给想要查看它们的用户.现在我在自己的机器上托管服务器,所以指南中的代码片段将文件写入我的D:驱动器,这不是(而不是)可以从Internet获得.据我所见,有两个选择:>将照片存储在我的项目中的/ public文件夹中(专用于资产的文件夹).见:
我试图允许用户将照片上传到服务器,然后查看它们.上传按照 in this guide

所述进行操作.这是代码:

def upload = Action(parse.multipartFormData) { request =>
  request.body.file("picture").map { picture =>
    import java.io.File
    val filename = picture.filename 
    val contentType = picture.contentType
    picture.ref.moveTo(new File("/tmp/picture"))
    Ok("File uploaded")
  }.getOrElse {
    Redirect(routes.Application.index).flashing(
      "error" -> "Missing file"
    )
  }
}

我不清楚如何将上传的图像提供给想要查看它们的用户.现在我在自己的机器上托管服务器,所以指南中的代码片段将文件写入我的D:驱动器,这不是(而不是)可以从Internet获得.据我所见,有两个选择:

>将照片存储在我的项目中的/ public文件夹中(专用于资产的文件夹).见: http://www.playframework.org/documentation/2.0/Assets

>编写我自己的控制器,从我的驱动器的自定义位置服务图像.

对于1,我不知道这是否是资产的目的.

对于2,我不知道如何写这样一个控制器.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Semi-Supervised Learning

Introduction to Semi-Supervised Learning

Xiaojin Zhu、Andrew B. Goldberg / Morgan and Claypool Publishers / 2009-6-29 / USD 40.00

Semi-supervised learning is a learning paradigm concerned with the study of how computers and natural systems such as humans learn in the presence of both labeled and unlabeled data. Traditionally, le......一起来看看 《Introduction to Semi-Supervised Learning》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码