我正在使用带有C#和Azure的Web Api 2,以及如何返回图像(从Memorystream基础)以便在页面上显示的问题...
这是我的Controller HTTPGET
[Route("api/PhotoSubmit/GetPhoto/{id}")]
[HttpGet]
public HttpResponseMessage GetPhotoById(int id)
{
StorageServices storage = new StorageServices();
MemoryStream ms = storage.DownloadBlob(id);
// return what ?
}
Run Code Online (Sandbox Code Playgroud)
这是servicecall的开头:
$http({
method: 'GET',
url: 'api/PhotoSubmit/GetPhoto/' + $routeParams.id,
accept: 'application/json'
})
.success(function(result) {
// How do i handle the result and what HTML should i use ? <img ?
});
Run Code Online (Sandbox Code Playgroud) 我正在使用Azure开发Blob存储..
上传blob工作得很好,我可以双击visual studio blob容器视图中上传的图像并打开图片...
但如果你看看这张照片:
...... Uri有问题吗?
这是我正在使用的代码:
public MemoryStream DownloadBlob(int id)
{
Photo photo = PhotoServices.GetPhotoById(id);
var cloudBlobContainer = _blobClient.GetContainerReference(CurrentBlobContainerName);
var blob = cloudBlobContainer.GetBlockBlobReference(photo.BlobUrl);
var memorystream = new MemoryStream();
// THIS LINE GIVES BLOB NOT FOUND EXCEPTION
blob.DownloadToStream(memorystream);
memorystream.Position = 0;
return memorystream;
Run Code Online (Sandbox Code Playgroud)
这是我如何存储blob:
public CloudBlockBlob UploadBlob(Stream fileStream, string fileName)
{
var blobName = Guid.NewGuid() + fileName;
var blockBlob = GetContainer().GetBlockBlobReference(blobName);
blockBlob.UploadFromStream(fileStream);
return blockBlob;
}
Run Code Online (Sandbox Code Playgroud)
这是我如何得到blob:
public MemoryStream DownloadBlob(int id)
{
Photo photo = PhotoServices.GetPhotoById(id);
var cloudBlobContainer = _blobClient.GetContainerReference(CurrentBlobContainerName); …
Run Code Online (Sandbox Code Playgroud) 我需要使用Stream(Azure Blobstorage)上传文件,而无法找到如何从对象本身获取流.见下面的代码.
我是WebAPI的新手,并使用了一些示例.我正在获取文件和filedata,但我的方法上传它并不正确.因此,我需要将其转换或转换为普通Stream,此刻看起来有点难:)
我知道我需要以ReadAsStreamAsync().Result
某种方式使用,但它在foreach循环中崩溃,因为我得到两个provider.Contents(第一个似乎正确,第二个没有).
[System.Web.Http.HttpPost]
public async Task<HttpResponseMessage> Upload()
{
if (!Request.Content.IsMimeMultipartContent())
{
this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
var provider = GetMultipartProvider();
var result = await Request.Content.ReadAsMultipartAsync(provider);
// On upload, files are given a generic name like "BodyPart_26d6abe1-3ae1-416a-9429-b35f15e6e5d5"
// so this is how you can get the original file name
var originalFileName = GetDeserializedFileName(result.FileData.First());
// uploadedFileInfo object will give you some additional stuff like file length,
// creation time, directory name, a few filesystem methods etc..
var uploadedFileInfo = new FileInfo(result.FileData.First().LocalFileName); …
Run Code Online (Sandbox Code Playgroud) 我正在努力寻找片刻.js"查询"以确定日期(例如:2014年10月12日)是否在"今天"前一天或"今天"后两天.
谷歌搜索,并检查moment.js文档,但没有找到任何正确或可理解的如何做到这一点的例子...
已经在谷歌上搜索了很长一段时间来弄清楚如何做到这一点..
我有一个“意图”列表,每个人都有一个“实体”列表,以嵌套的 v-for 形式呈现。
已经计算了意图,但我还需要即时对“实体”列表进行排序,因此我认为制作该列表也计算了..
错误 :
**TypeError: _vm.entityList is not a function**
Run Code Online (Sandbox Code Playgroud)
这是我目前的方法:
**TypeError: _vm.entityList is not a function**
Run Code Online (Sandbox Code Playgroud)
< script >
import uniq from 'lodash/uniq'
import orderby from 'lodash/orderby'
import Util from "@/components/util.js"
export default {
data() {
return {
// ....
}
},
computed: {
nluData() {
return orderby(this.$store.getters.nlujson.filter(item => {
return item.intent.toLowerCase() === this.selectedIntent
}), ['intent', 'text'], ['asc', 'asc'])
},
entityList(item) {
return orderby(item.entities, ['entity', 'value'], ['asc', 'asc'])
},
},
created() {
this.$store.dispatch('getNluJson')
},
methods: { …
Run Code Online (Sandbox Code Playgroud)任何人都知道我为什么在这个Angular代码上获得Unknown provider?
我正在使用Angular File Upload指令并使用此示例:
只是似乎无法弄清楚为什么我收到这个错误...
module.js文件:
angular.module('photoApp', ['ngRoute']);
Run Code Online (Sandbox Code Playgroud)
scripts.js文件:
// configure our routes
angular.module('photoApp').config(function ($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'Pages/home.html',
controller: 'mainController'
})
// route for the contact page
.when('/uploadphoto', {
templateUrl: 'Pages/photoupload.html',
controller: 'photoUploadController'
});
});
// create the controller and inject Angular's $scope
angular.module("photoApp").controller('photoUploadController',
function ($scope, $http, $timeout, $upload) {
$scope.message = 'Upload your photo';
$scope.upload = [];
$scope.fileUploadObj = { testString1: "Test string 1", testString2: "Test string 2" …
Run Code Online (Sandbox Code Playgroud) 这很好,可能会被标记为重复,如果是对不起.谷歌搜索了很多,以找到如何实际做到这一点,没有任何适当的解决方案(虽然我不是一个vue专家..)
基本上......我正在尝试做什么..从api => store => vue组件传递成功或失败.如果错误...我将向用户显示错误代码(暂时...)
事情的方式..
1)从vue组件触发的方法.派送到$ store(modal.vue)
2)触发状态动作以设置突变类型和调用API.
3)调用Api方法.
4)返回成功或错误,和http.statuscode ....
MODAL.VUE
doRefund: function(){
this.$store.dispatch('doRefund', {
Username : this.loggedInUser.account.username,
OrderID: this.selectedOrder.orderid,
IsFeeApplied: false,
CreditAmount: this.refundAmount,
ChargeFee: 0.0,
Reason: "reason-not-specified",
Description: this.comment,
BearerToken: "Bearer " + this.accessToken
})
.then(result => {
if(result === true){
alertify.success('It worked!')
}
else{
alertify.alert('There was an error, and the errorcode is' + errorcode ????)
}
})
}
Run Code Online (Sandbox Code Playgroud)
STORE.JS
doRefund({ commit }, refundParams){
api.tryRefund(refundParams)
.then(refundCompleted => {
commit(types.SET_REFUND_COMPLETED, true)
return true;
})
.catch(err …
Run Code Online (Sandbox Code Playgroud) 老实说.. 我对 node 和 process.env 的东西有点陌生.. 可能有一个很好的解释来解释我的问题,但我还没有找到它。
任务 :
将用户名和密码存储在 env.js 文件中,以便我可以检查我的 store.js 文件中的那些...
当前方法:
webpack.base.conf.js
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
var webpack = require('webpack');
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
plugins: [
new webpack.DefinePlugin({
'process.env': {
loginEmail: "xxxxx",
loginPw: "xxxxxx"
}
})
],
.... rest is default/unchanged
Run Code Online (Sandbox Code Playgroud)
错误 :
我还没有进入我实际访问 process.env.loginEmail 的部分,但我认为它是这样的(在组件或 store.js 中):
console.log("Process listings ==>")
console.log("loginEmail : " …
Run Code Online (Sandbox Code Playgroud) javascript ×4
c# ×3
vue.js ×3
vuejs2 ×3
angularjs ×2
azure ×2
axios ×1
filestream ×1
http-get ×1
memorystream ×1
momentjs ×1
node.js ×1
webkit ×1