我正在使用Multer在Express 4中上传图像.但是,这些示例都显示Multer在Express文件中被定义为Middleware.我想在我的应用程序路由本身中实际定义一些Multer行为.这可能吗?我需要的最终结果是我的路由功能在将服务器响应发送到浏览器之前识别上传完成的时间,因此可以向用户显示图像(现在我只显示部分图像,因为该文件尚未完成上传).
当前的工作代码
express.js
// Require Multer as module dependency.
var multer = require('multer');
// Using Multer for file uploads.
app.use(multer({
dest: './public/profile/img/',
limits: {
fieldNameSize: 50,
files: 1,
fields: 5,
fileSize: 1024 * 1024
},
rename: function(fieldname, filename) {
return filename;
},
onFileUploadStart: function(file) {
if(file.mimetype !== 'image/jpg' && file.mimetype !== 'image/jpeg' && file.mimetype !== 'image/png') {
return false;
}
}
}));
Run Code Online (Sandbox Code Playgroud)
server_routes.js
app.route('/users/image').post(server_controller_file.imageUpload);
Run Code Online (Sandbox Code Playgroud)
server_controller_file.js
exports.imageUpload = function(req, res) {
// Check to make sure req.files contains …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 SpannableString 在单个 TextView 中格式化大块文本。大小和颜色的格式都很好,但我在对齐方面遇到了困难。
我发现这篇文章提供了有关对齐格式的指导,以及有关如何使用 AlignmentSpan 的Android 开发人员页面,但它似乎对我不起作用。Eclipse 没有显示任何错误,应用程序加载/运行得很好,但对齐部分似乎完全被忽略了。这是我的代码:
Spannable t = new SpannableString("Test Blue.");
t.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_blue)), 0, t.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
t.setSpan(new AbsoluteSizeSpan((int) getResources().getDimension(R.dimen.big_text)), 0, t.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
t.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, t.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text3.setText(t);
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激。
[编辑] 我还尝试注释掉颜色和大小 setSpans 以查看是否存在冲突,但没有运气。
[编辑2]:我将下面的答案标记为正确的,但正确的答案实际上隐藏在评论中。我无法将 TextView 的 XML 文件宽度更新为 match_parent(而不是 fill_content)。谢谢塞尔吉!
我正在努力制作一款游戏来帮助孩子们学习数学.我为代码编号,以便他们可以遵循逻辑.我还使用textView.append()来构建一个长字符串以放入活动中.
因为我在指令中重复使用相同的数字/符号,我想要一种方法来轻松回收SpannableStrings,但似乎我所做的更改在第一次正确应用,但此后有时工作,有时部分工作(例如正确的大小)/alignment,但颜色错误),或根本不工作.我正在混合这一切.我似乎无法在Stackoverflow或Google上的任何其他地方找到遇到类似问题的人.
这是我的代码(简化):
// Declare static variables
public static Spannable PLUS = new SpannableString("+ ");
public static Spannable MINUS = new SpannableString("- ");
public static Spannable TIMES = new SpannableString("X ");
public static Spannable DIVIDED_BY = new SpannableString("/ ");
public static Spannable EQUALS = new SpannableString("= ");
// Function to color these strings.
public void colorStrings() {
makeBlack(PLUS);
makeBlack(MINUS);
makeBlack(TIMES);
makeBlack(DIVIDED_BY);
makeBlack(EQUALS);
makeBlack(QMARK);
}
// Function that actually sets color, size, and alignment.
public Spannable makeBlack(Spannable s) {s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_black)), 0, …Run Code Online (Sandbox Code Playgroud)