score:25
1) it is ok to put uploading into separate method, it could also be put into a separate class for handling blob operations
2) file
is the name of one of the controllers methods, if you want to reference the file
class from system.io namespace, you need to fully qualify the name
filestream uploadfilestream = system.io.file.openread(localfilepath);
to the other compile error, you need to return something from the uploadtoblob
method, now it does not return anything from the try
block
3) file type validation can be put into the controller action method
4) it depends on what you plan to do with the text and how are you going to use it. would it be a new action of the controller (a new api endpoint)?
5) you could create a new api endpoint for downloading files
update:
for word replacement you could use a similar method:
private stream findmostfrequentwordandreplaceit(stream inputstream)
{
using (var sr = new streamreader(inputstream, encoding.utf8)) // what is the encoding of the text?
{
var alltext = sr.readtoend(); // read all text into memory
// todo: find most frequent word in alltext
// replace the word alltext.replace(oldvalue, newvalue, stringcomparison)
var resulttext = alltext.replace(...);
var result = new memorystream();
using (var sw = new streamwriter(result))
{
sw.write(resulttext);
}
result.position = 0;
return result;
}
}
it would be used in your post method this way:
using (var stream = formfile.openreadstream())
{
var streamwithreplacement = findmostfrequentwordandreplaceit(stream);
// upload the replaced text:
(uploadsuccess, uploadeduri) = await uploadtoblob(formfile.filename, null, streamwithreplacement);
}
score:5
you probably have this method inside mvc controller in which file method exists. add in your code system.io.file
instead of file
Source: stackoverflow.com
Related Query
- 'ControllerBase.File(byte[], string)' is a method, which is not valid in the given context (CS0119) - in method
- my javascript string is like this: "accepted === accepted && 50 > 100" Now I have to return boolean ans about this string which is valid or not
- Yup.string.when will always give the result undefined. How can i pass a string value into the .when method
- Invariant Violation: Objects are not valid as a React child. Check the render method of `Content`
- The useState set method is not reflecting a change immediately
- Why does calling react setState method not mutate the state immediately?
- The token '&&' is not a valid statement separator in this version
- InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('/static/media/index.c6592bb6.ts') is not a valid name
- React-router: changing query string does not re-mount the component
- Reactjs Warning: input is a void element tag and must not have `children` or use `props.dangerouslySetInnerHTML`. Check the render method of null
- Why does jest-dom give the error "TypeError: expect(...).not.toBeVisible is not a function" when I use it
- getNode() method not found in gatsby-node.js with the latest version of Gatsby
- Required context `router` was not specified. Check the render method of `RoutingContext`
- passed to parser was not a valid GraphQL DocumentNode.you may need to use 'graphql-tag' or another method to convert your operation into a document
- TypeError: "Cannot convert string to ByteString because the character at index 519 has value 8230 which is greater than 255."
- Jest-dom give the error "TypeError: expect(...).toHaveStyle is not a function"
- Warning: Failed propType: Required prop `dimensionName` was not specified in `DimensionPicker`. Check the render method of `Connect(DimensionPicker)`
- How to properly make a GET call in React returning an observable (resembling the method in Angular and not using promises)?
- Module not found: You attempted to import which falls outside of the project src/ directory. Relative imports outside of src/ are not supported
- The `style` prop expects a mapping from style properties to values, not a string
- Render method does not re-render element initialized in the constructor
- The resetForm method of Formik does not work as expected
- check if the key in an object is string or not when using prop-types
- Preact error: "objects are not valid as a child. Encountered an object with the keys {}" when using async await in root component
- useState set method not changing the value - React
- not able to clear Interval using variable which is outside the react hook
- React: SlickGrid requires a valid container, #myGrid does not exist in the DOM
- React error: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node
- Test of reducer returns the results which are not equal to expected
- Module not found: Error: You attempted to import babel-preset which falls outside of the project src/ directory
More Query from same tag
- Can't get Webpack 2 HMR React to work
- Indent Entry in React-Select Values
- Cycling through count in React component
- How to add your own custom css to override react-confirm-alert defaults
- Next.js not auto refreshing
- React- Render two different data arrays in a single card
- call react function inside anonymous function
- I am trying copy the image to canvas using the html2canvas but its not working
- When to use React createFragment?
- Automatically signout users using Firebase
- importing images into ReactJS programmatically?
- React / Partially sticky footer
- How can the render be synced with the state on pagination click with react?
- Reactjs default Form validation with event.preventDefault()
- Typescript : how to use every props from a type except one
- ReactJS v4 routing
- MERN pagination and filtering in same controller
- TypeError: Cannot read properties of undefined (reading 'map') Trying to Read REST api and display
- How to push the existing DOM element when a new element is created dynamically using javascript
- How to create moving text from right to left using react-spring?
- Loop with componentDidUpdate
- CSS translate X causes white space on right side of screen mobile
- Update value of a object in an array
- Object keys loop not rendering in React
- How do I get hover effect on rows with material-table react?
- Using rsuite to draw a table in react
- How to read text file in react
- React delaying render while fetch call populates Redux store
- Can't get MemoryRouter to work with @testing-library/react
- Refresh data received from an API every minute React, Javascript