我想用 Lift 实现一个图像升级。从这个开始。我是电梯的新手。
我做了一些修改。现在我只想看到一些有效的东西。不一定是图像。到目前为止,我有:
package code
package snippet
import net.liftweb.http.S
import net.liftweb.common.Full
import net.liftweb.common.Empty
import net.liftweb.common.Box
import net.liftweb.http.FileParamHolder
import net.liftweb.util._
import Helpers._
import scala.xml.Group
import scala.xml.NodeSeq
import net.liftweb.http.SHtml
class AddEntry {
// Add a variable to hold the FileParamHolder on submission
var fileHolder : Box[FileParamHolder] = Empty
def doTagsAndSubmit (t : String) {
// val e : Expense = ...
// Add the optional receipt if it’s the correct type
val receiptOk = fileHolder match {
// An empty upload gets reported with a null mime type,
// so we need to handle this special case
case Full(FileParamHolder(_, null, _, _)) => true
case Full(FileParamHolder(_, mime, _, data))
if mime.startsWith("image/") => {
// e.receipt(data).receiptMime(mime)
true
}
case Full(_) => {
S.error("Invalid receipt attachment")
false
}
case _ => true
}
// (e.validate, receiptOk) match {
// }
}
def addEntry(content: NodeSeq): NodeSeq = {
bind("prefix", content,
"receipt" -> SHtml.fileUpload(fileHolder = _)) //compiler error: type mismatch; found : net.liftweb.http.FileParamHolder required: net.liftweb.common.Box[net.liftweb.http.FileParamHolder]
}
}
的HTML:
<lift:AddEntry.addEntry form="POST" multipart="true">
<td>Receipt (JPEG or PNG)</td>
<td><prefix:receipt /></td>
</lift:AddEntry.addEntry>
正如在代码中评论的那样,我遇到"receipt" -> SHtml.fileUpload(fileHolder = _)
了编译器错误:错误:类型不匹配;找到:net.liftweb.http.FileParamHolder 需要:net.liftweb.common.Box[net.liftweb.http.FileParamHolder]
不明白,因为 fileHolder 是Box[FileParamHolder]
. 它应该与表达式有关fileHolder = _
,但不知道如何。
提前致谢。