using Azure.Storage; using Azure.Storage.Blobs; using Azure.Storage.Blobs.Models;
... public Task<bool> UploadFileToStorage(Stream fileStream){ // Create a URI to the blob Uri blobUri = new Uri("https://" + _storageConfig.AccountName + ".blob.core.windows.net/" + _storageConfig.ImageContainer + "/" + fileName); // connection credential StorageSharedKeyCredential storageCredentials = new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey);
// Create the blob client. BlobClient blobClient = new BlobClient(blobUri, storageCredentials);
// Upload the file await blobClient.UploadAsync(fileStream);
return await Task.FromResult(true); }
public static async Task<List<string>> GetThumbNailUrls(AzureStorageConfig _storageConfig) { List<string> thumbnailUrls = new List<string>();
// Create BlobServiceClient from the account URI BlobContainerClient container = new BlobContainerClient(connectionString, _storageConfig.ThumbnailContainer);
// Get reference to the container BlobContainerClient container = blobServiceClient.GetBlobContainerClient(_storageConfig.ThumbnailContainer);
if (container.Exists()) { foreach (BlobItem blobItem in container.GetBlobs()) { thumbnailUrls.Add(container.Uri + "/" + blobItem.Name); } }
let _state; function useState(initialState) { _state = _state || initialState; // 如果存在旧值则返回, 使得多次渲染后的依然能保持状态。 function setState(newState) { _state = newState; render(); // 重新渲染,将会重新执行 Counter } return [_state, setState]; }
useEffect Effect是指获取数据,订阅,Dom操作等。useEffect跟 class 组件中的 componentDidMount、componentDidUpdate 和 componentWillUnmount 具有相同的用途,只不过被合并成了一个 API,即组件在初始化完成、重新渲染、即将销毁时执行useEffect指定的逻辑。
1 2 3 4 5 6 7 8 9 10
/** * Accepts a function that contains imperative, possibly effectful code. * * @param effect Imperative function that can return a cleanup function * @param deps If present, effect will only activate if the values in the list change. * * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#useeffect */ function useEffect(effect: EffectCallback, deps?: DependencyList): void;
useEffect(() => { function handleStatusChange(status) { setIsOnline(status.isOnline); } ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange); // Specify how to clean up after this effect: return () => { ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange); }; });
yarn install is used to install all dependencies for a project. This is most commonly used when you have just checked out code for a project, or when another developer on the project has added a new dependency that you need to pick up. If you are used to using npm you might be expecting to use —save or —save-dev. These have been replaced by yarn add and yarn add —dev. For more information, see the yarn add documentation.
Running yarn with no command will run yarn install, passing through any provided flags.
Error: Your application tried to access XXX but it isn’t declared in your dependencies; this makes the require call ambiguous and unsound 疑因使用nvm导致存在冲突的yarn cache路径,导致程序并没有按yarn.lock确定所需的依赖包,该问题在卸载nvm,删除%USERPROFILE%\AppData\Local\Yarn\Berry文件并重装nodejs后解决